Forum Moderators: phranque
I have added this piece of code to my .htaccess file with the hope of redirecting mysite.com to www.mysite.com
########## Begin - 301 Redirect
#
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST}!^www\.mysite\.com$
RewriteRule ^(.*)$ [mysite.com...] [R=301,L]
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /(([^/]+/)*)index\.php\ HTTP/
RewriteRule index\.html$ [mysite.com...] [R=301,L]
#
########## End - 301 Redirect
This works fine, with the exception that now my subdomains such as blog.mysite.com now redirect to a 404 error page.
What am I doing wrong?
########## Begin - 301 Redirects
#
RewriteEngine on
RewriteBase /
#
# Redirect client requests for "/index.html" to "/" in same directory
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /(([^/]+/)*)index\.php(\?[^\ ]*)?\ HTTP/
RewriteRule index\.html$ http://www.example.com/%1 [R=301,L]
#
# Redirect requests for example.com to corresponding page on www.example.com
RewriteCond %{HTTP_HOST} ^example\.com(:[0-9]+)?$
RewriteRule (.*) http://www.example.com/$1 [R=301,L]
#
########## End - 301 Redirects
Jim
On one line it tests for index.php and on another for index.html instead.
.
I have seen this longer code that caters for most known index names:
# Index redirection
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /([^/]*/)*index\.(html?地spx?夸spx?圭gi如l如hp[2-5]圭fm)[^\ ]*\ HTTP/
RewriteRule ^(([^/]*/)*)index\.(html?地spx?夸spx?圭gi如l如hp[2-5]圭fm)$ http://www.example.com/$1? [R=301,L]
There are multiple ways to get the job done.