How to make a correct htaccess 301 redirect

I have a blog that is installed in a folder. Basically, let’s say my blog is installed in www.example.com/folder/
I would like to have correct 301 redirects as it follows:

example.com -> www.example.com/folder/
www.example.com -> www.example.com/folder/
example.com/index.php -> www.example.com/folder/
www.example.com -> www.example.com/folder/

I have two htaccess files (one in / and one in /folder). The one in /folder is updated by wordpress.

Read More

htaccess in root:

RewriteCond %{REQUEST_URI} !^/carte/
RewriteCond %{HTTP_HOST} ^(www.)?cemaicitesc.
RewriteRule ^(.*)$ /carte/$1 [L] 

htaccess in /folder:

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /carte/
RewriteRule ^index.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /carte/index.php [L]
</IfModule> 

Currently, if I type in the browser example.com, it stays on example.com.

Can you help? I always have hard time using htaccess redirects so I prefer to ask before testing.

Thank you!

Related posts

1 comment

  1. Just try change RewriteRule in root .htaccess

    RewriteRule ^(.*)$ http://www.example.com/carte/$1 [R=301,L]
    

    Where http://www.example.com is your domain name with www prefix

    R=301 make redirect. In your example you just rewrite URL.

Comments are closed.