Page is a not externally linkable
- Code, Content, and Presentation
-- Apache Web Server
---- rewrite to www.site with modx dynamic seo urls


lizardx - 4:23 am on Feb 4, 2008 (gmt 0)


I've been trying to figure this one out, and I just can't see how to do it.

modx has some nice search engine friendly urls, the goal here is to get all urls to get a www prepended if absent.

So far, I'm doing this, the site is being developed, and this works, but fails to create the www except for / requests.

Also, this seems very hackish, I know there must be a better way to get even that done:

RewriteCond %{REQUEST_URI} ^/$
RewriteCond %{HTTP_HOST}!^www\.example\.com [NC]
RewriteRule ^(.*)$ http://www.example.com/ [R=301,L]

RewriteCond %{REQUEST_FILENAME} -f
RewriteCond %{REQUEST_FILENAME} -d
RewriteCond %{HTTP_HOST}!^www\.example\.com [NC]
RewriteRule ^(.*)$ http://www.example.com/$1 [R=301,L]

RewriteCond %{REQUEST_FILENAME}!-f
RewriteCond %{REQUEST_FILENAME}!-d
RewriteRule ^(.*)$ index.php?q=$1 [QSA]

I'm just using this for now until I get it actually running.

Requests for http: //example.com/ are correctly rewritten to http: //www.example.com/

Requests for internal pages are ignored, not being either -f or -d, and are handled by the QSA rule.

However, the goal here would be to get requests for example.com/some/virtual/url rewritten to www.example.com/some/virtual/url

I've tried a variety of permutations, but if I remove the -f and -d conditions, I get an internal modx 404 error page, which I can then follow the navigation out of and surf the site. Currently actual nav links are are done to a base url of www.example.com, so it only seems to the first landing page that causes the problem.

Hopefully this is clear.


Thread source:: http://www.webmasterworld.com/apache/3565542.htm
Brought to you by WebmasterWorld: http://www.webmasterworld.com