Forum Moderators: phranque

Message Too Old, No Replies

Problem with subdomain a rewrite from non www to www site

My rewrite condition redirect the subdomain to main domain

         

jmesam

3:15 am on Nov 4, 2005 (gmt 0)

10+ Year Member



Hi!
I have 2 things in my htaccess:

#1. rewrite all /myfiles.php to /myfiles
#2. redirect from [mydomain.com...] to [mydomain.com...]


#1#############################################
RewriteEngine On
RewriteBase /
# remove .php; use THE_REQUEST to prevent infinite loops
RewriteCond %{THE_REQUEST} ^GET\ (.*)\.php\ HTTP
RewriteRule (.*)\.php$ $1 [R=301]
# remove index
RewriteRule (.*)/index$ $1/ [R=301]
# remove slash if not directory
RewriteCond %{REQUEST_FILENAME}!-d
RewriteCond %{REQUEST_URI} /$
RewriteRule (.*)/ $1 [R=301]
# add .php to access file, but don't redirect
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteCond %{REQUEST_URI}!/$
RewriteRule (.*) $1\.php [L]

#2#############################################

RewriteEngine On
RewriteCond %{HTTP_HOST} ^mydomain.com
RewriteRule (.*) [mydomain.com...] [R=301,L]

The #1 run ok, but #2 do all these strange things:

I write -> It shows

[mydomain.com...] -> [mydomain.com...] (note the index.htm I have only index.php on my server)
[mydomain.com...] -> [mydomain.com...]
[mysubdomain.mydomain.com...] -> [mydomain.com...] (note there's not index.htm)
[mysubdomain.mydomain.com...] -> [mysubdomain.mydomain.com...]

I don't know what happen with my mod_rewrite file.

Any help?

Thank you in advance,

jd01

8:10 am on Nov 4, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Appears to be an order problem with your rules -- I would re-order my rulesets and remove the second RewriteEngine line, and try again...

EG
RewriteEngine on

RewriteCond %{HTTP_HOST} ^mydomain.com
RewriteRule (.*) http://www.mydomain.com/$1 [R=301,L]

RewriteBase /
# remove .php; use THE_REQUEST to prevent infinite loops
RewriteCond %{THE_REQUEST} ^GET\ (.*)\.php\ HTTP
RewriteRule (.*)\.php$ $1 [R=301]
# remove index
RewriteRule (.*)/index$ $1/ [R=301]
# remove slash if not directory
RewriteCond %{REQUEST_FILENAME}!-d
RewriteCond %{REQUEST_URI} /$
RewriteRule (.*)/ $1 [R=301]
# add .php to access file, but don't redirect
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteCond %{REQUEST_URI}!/$
RewriteRule (.*) $1\.php [L]

Hope this helps.

Justin

BTW I did not analyze this one for too long, the order was the first thing that jumped out at me, so if it does not correct the issue, please let us know. I might also consider adding other methods to the THE_REQUEST line, but am not sure why it is limited to GET -- maybe there is a reason?

jmesam

5:49 pm on Nov 4, 2005 (gmt 0)

10+ Year Member



Thank you for your support, I clear my browser's cache and change the order of the rulesets and it ok.

About the GET in the THE_REQUEST line I don't know why it's there. I'm just "copy&paste" the code from another site (I don't remeber which)

Regards,
Jorge