Forum Moderators: phranque
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST}!^www\.example\.com
RewriteRule (.*) http://www.example.com/$1 [R=301,L]
Now when someone requests mydomain.com/blah.html it redirects to www.mydomain.com/blah.html (WITH the www).
Today I installed wordpress. It's located at www.mydomain.com/blog.
What I'm trying to do now is make it so a request for mydomain.com/blog (or mydomain.com/blog/2006-post-title/ gets redirected to www.mydomain.com/blog/whatever (WITH the www).
I'm assuming it should be done with a new .htaccess file in the blog directory, right? I've tried for a while but the closest I can get is having mydomain.com/blog redirect to www.mydomain.com. Apparently I'm doing something wrong.
Help would be greatly appreciated. Thanks.
[edited by: jdMorgan at 10:38 pm (utc) on June 26, 2006]
[edit reason] example.com [/edit]
Or perhaps it installed a rewriterule in your .htaccess file positioned *above* the domain redirect. Either way, it's down to something interfering with your existing rule.
Without more info on the WordPress/server setup, it's impossible to tell. If you are getting errors, take a look at the server error log; it may be quite helpful.
Jim
You may delete any redundant code, such as multiple RewriteEngine on and Options directives -- Only one each of these is needed at the top of the mod_rewrite code.
Jim
RewriteEngine On
RewriteBase /
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /(([^/]+/)*)index\.html\ HTTP/
RewriteRule index\.html$ http://www.example.com/%1 [R=301,L]
RewriteCond %{HTTP_HOST} !^www\.example\.com
RewriteRule (.*) http://www.example.com/$1 [R=301,L]
<IfModule mod_rewrite.c>
RewriteBase /blog/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /blog/index.php [L]
</IfModule>
Should everything work correctly now?
Thanks again for your help.
[edited by: jdMorgan at 10:39 pm (utc) on June 26, 2006]
[edit reason] example.com [/edit]
I'd encourage you to test it, rather than asking a question here which only testing can answer... :)
Jim
P.S. You can delete the <IfModule> container. It's redundant in that if mod_rewrite isn't loaded, then the code won't run. But I think you'd *want* the resulting error message if mod_rewrite wasn't loaded, rather than a silent failure.