mod_rewrite pretty urls and canonical hostname

For questions and problems with the CMS core. This board is NOT for any 3rd party modules, addons, PHP scripts or anything NOT distributed with the CMS made simple package itself.
Locked
mta

mod_rewrite pretty urls and canonical hostname

Post by mta »

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.

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
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.

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
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
Pierre M.

Re: mod_rewrite pretty urls and canonical hostname

Post by Pierre M. »

Hello,
mta wrote: I am running CMSMS 1.0.8
(...)
For example if the client enters http://www.mydomain.com/test, he is redirected to http://www.mydomain.org...
you shouldn't run such an old insecure unsupported release on the wild Internet to satify your customers.
Don't stay alone, upgrade to 1.4.1. (search the forum for upgrade path from 1.0.z)

Pierre M.
Locked

Return to “CMSMS Core”