Forum Moderators: phranque
#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,
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?