The Ultimate .htaccess Smackdown ;)

Discussion in 'Site & Server Administration' started by gemini181, Nov 8, 2008.

  1. #1
    For consistently changing URL's with www to no www I've seen people suggest these formats for .htaccess:

    RewriteEngine on
    RewriteCond %{HTTP_HOST} !^example\.com$ [NC]
    RewriteRule .? http://example.com%{REQUEST_URI} [R=301,L]
    Code (markup):

    RewriteEngine On
    RewriteBase /
    RewriteCond %{HTTP_HOST} !^example.com$ [NC]
    RewriteRule ^(.*)$ http://example.com$1 [L,R=301]
    Code (markup):
    I have one in mind which "seems to work better with at least one host", and I'm interested in knowing which one you think is better, and why?

    Thank you.

    >>> EDIT: The main point is avoiding conflicts with scripts in sub-directories. <<<
     
    gemini181, Nov 8, 2008 IP