Forum Moderators: phranque
1. Add www to the domain if not inputted by user,
2. Send any requests to www.example.com to www.example.com/blog (including the already changed URLs from http://example.com).
I would like the /blog redirect only to work when the root is accessed so I can still have access to any subfolders to the root. (ie: /form).
I was able to get the first part working but not the second. Can anyone help me out?
Options +FollowSymLinks
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} ^www\.example\.com [NC]
RewriteRule ^(.*)$ http://www.example.com/$1 [L,R=301]
...
[edited by: jdMorgan at 3:42 pm (utc) on Aug. 9, 2008]
[edit reason] example.com [/edit]
Options +FollowSymLinks
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} ^example\.com [NC]
RewriteRule ^(.*)$ http://www.example.com/$1 [L,R=301]
RewriteRule ^$ http://www.example.eu/folder/
Options +FollowSymLinks
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} ^example\.com [NC]
RewriteRule ^(.*)$ http://www.example.com/$1 [L,R=301]
RewriteRule ^$ http://www.example.com/folder/
With this code, wheather the user types www.example.com or example.com, the www will be added. The last line redirects to /folder
No it doesn't. It redirects to /folder/
The last line should be a rewrite to /folder/ so you should remove the domain name from that last line, and add [L] to the end.
[edited by: jdMorgan at 8:46 pm (utc) on Aug. 11, 2008]
[edit reason] clarified text. [/edit]
In addition, any RewriteRules following this one will be executed before the redirect takes place, since the [L] flag is missing.
Be sure this is what you want.
Jim
RewriteCond %{HTTP_HOST} ^example\.eu [NC]
RewriteRule (.*) www.example.eu/deedee/$1 [L,R=301]
the first condition works but not the second?
[edited by: jdMorgan at 5:32 pm (utc) on Aug. 13, 2008]
[edit reason] examplified URLs [/edit]
In what way does your code not work? What did it do? What did you expect it to do? How does that differ from what you expected?
I assume you have tested it with a variety of URL formats, both for root and deep-URL requests, and for both of those for both www and non-www URLs.
so try this way,
RewriteCond %{HTTP_HOST} ^www\.example\.eu [NC]
RewriteRule ^$ /deedee/$1 [R=301]
RewriteCond %{HTTP_HOST} ^example\.eu [NC]
RewriteRule (.*) www.example.eu/deedee/$1 [L,R=301]
As for redirecting to a lower directory, it is common parctice and also if you get a "corrupted" folder, its easier to wipe on efolder than your whole webspace