0

Trying to figure out how to write my httaccess to let me have it so my urls are 'www' free and allow me to have a slug style setup for 'friendly' urls. I seem to keep writing myself into an internal 500 error though. That or it doesn't seem to carry over the extra stuff. extra stuf being anything from .com/ over ie mydomain.com/hello/world

RewriteEngine On
Options +FollowSymlinks -MultiViews
RewriteBase /
RewriteCond %{HTTP_HOST} ^www.mydomain.com [NC]
RewriteRule ^(.*)/?$ http://mydomain.com/index.php?r=$1

Overall goal take URL in either of these 2 fashions

http://mydomain.com/hello/world

http://www.mydomain.com/hello/world

and have it translate to

http://mydomain.com/hello/world to the front end but on the backend be the equivalent to http://mydomain.com/index.php?r=hello/world

also I would like to apply conditions where if a file exists, or folder exists, or whatever exists stop the rewrite cold. I know this is possible well without the removal of the www part, not sure with that part, as I used to once have an htaccess file that I could do this with, but I have lost that file and its been far to long since ive played with htaccess to remember how i did it in the first place.

4

1 回答 1

1

This will forward www to non-www site. Also take care of the index.php.

RewriteCond %{HTTP_HOST} ^www\.domain\.com$
RewriteRule ^(.*)$ http://domain.com/$1 [R=301,L]
RewriteRule ^(.*)$ index.php?r=$1 [QSA,L]

You can also add the following two lines. Like this if you have any css or images it will not rewrite them to index.php:

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

This is not tested but a general guidance.

于 2012-06-08T22:56:51.833 回答