mod_rewrite pretty urls and canonical hostname
Posted: Wed Aug 27, 2008 5:29 pm
My issue is basically the same as that posted in this thread: http://forum.cmsmadesimple.org/index.ph ... 203.0.html, but I am starting a new topic since that one has not been updated in some time.
I am running CMSMS 1.0.8 on Apache 2.0.52.
I have pretty urls working using the mod_rewrite method. I want to add a coexisting rewrite rule to redirect all traffic for mydomain.{com,net} to mydomain.org while preserving pretty urls.
When placing the canonical hostname rewrite rule before the pretty url rule, I get the 404 error page when visiting http://www.mydomain.com.
If I place the canonical hostname rule after the pretty urls rule, the desired result is almost achieved - except that redirected urls are not pretty.
For example if the client enters http://www.mydomain.com/test, he is redirected to http://www.mydomain.org/?page=test instead of http://www.mydomain.org/test.
Could anyone point me in the right direction?
Thank you!
- Michael
I am running CMSMS 1.0.8 on Apache 2.0.52.
I have pretty urls working using the mod_rewrite method. I want to add a coexisting rewrite rule to redirect all traffic for mydomain.{com,net} to mydomain.org while preserving pretty urls.
When placing the canonical hostname rewrite rule before the pretty url rule, I get the 404 error page when visiting http://www.mydomain.com.
Code: Select all
RewriteEngine On
# canonical host name
RewriteCond %{HTTP_HOST} !^www\.mydomain\.org [NC]
RewriteCond %{HTTP_HOST} !^$
RewriteRule .* http://www.mydomain.org$1 [R=301]
#Rewrites page.shtml as index.php?page
RewriteCond %{REQUEST_FILENAME} !-f [NC]
RewriteCond %{REQUEST_FILENAME} !-d [NC]
RewriteRule ^(.+)$ index.php?page=$1 [QSA]
#Error Pages
ErrorDocument 404 /invalid-address
Code: Select all
RewriteEngine On
#Rewrites page.shtml as index.php?page
RewriteCond %{REQUEST_FILENAME} !-f [NC]
RewriteCond %{REQUEST_FILENAME} !-d [NC]
RewriteRule ^(.+)$ index.php?page=$1 [QSA]
# canonical host name
RewriteCond %{HTTP_HOST} !^www\.mydomain\.org [NC]
RewriteCond %{HTTP_HOST} !^$
RewriteRule .* http://www.mydomain.org$1 [R=301]
#Error Pages
ErrorDocument 404 /invalid-address
Could anyone point me in the right direction?
Thank you!
- Michael