Forum Moderators: phranque
This is what I currently have written:
Options +FollowSymLinks
RewriteEngine on
RewriteCond %{HTTP_HOST} ^www.example.com [NC]
RewriteRule ^([^/]+)/$ http://example.com/$1 [L,R=301]
If anyone could help and let me know what changes I need to make that would be great.
[edited by: jdMorgan at 8:05 pm (utc) on Aug. 11, 2008]
[edit reason] example.com [/edit]
This function is usually done using the DirectoryIndex directive, but if you've done it with a rewrite or a redirect, then that directive and your rule are likely interacting. Otherwise, there is no reason for /index.php to appear in the URL.
Jim
#DirectoryIndex index.php index.html
#Options +FollowSymLinks
#Options -Indexes
<IfModule mod_rewrite.c>
RewriteEngine On
#RewriteBase /relative/web/path/
RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^(.+) - [PT,L]
RewriteRule ^(.*) index.php
RewriteCond %{HTTP:Authorization} !^$
RewriteRule .* - [E=REMOTE_USER:%{HTTP:Authorization}]
</IfModule>
#php_value register_globals 0
RewriteCond %{HTTP_HOST} ^.*$
RewriteRule ^/?$ "http\:\/\/www\.example\.com" [R=301,L]
Options +FollowSymLinks
RewriteEngine on
RewriteCond %{HTTP_HOST} ^www.example.com [NC]
RewriteRule ^([^/]+)/$ http://example.com/$1 [L,R=301]
DirectoryIndex index.php
#
Options +FollowSymLinks
RewriteEngine on
#
# Redirect to remove "<any_directory>/index.php" from search results
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /([^/]+/)*index\.php
RewriteRule ^(([^/]+/)*)index\.php$ http://example.com/$1 [R=301,L]
#
# Redirect to force canonical non-www domain name
RewriteCond %{HTTP_HOST} !^www\.example\.com$
RewriteRule (.*) http://example.com/$1 [R=301,L]
#
# If Authorization is not blank, copy it to Remote_User
RewriteCond %{HTTP:Authorization} !^$
RewriteRule .* - [E=REMOTE_USER:%{HTTP:Authorization},L]
#
# If requested URL does not resolve to existing file or directory, rewrite it to /index.php
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
The HTTP_Authorization rule is not likely to work, since mod_rewrite usually cannot be used to modify server variables -- I don't think you can change "Remote_User".
I removed the <IfModule> container, since the code would fail silently if mod_rewrite wasn't installed and that container was in place.
I re-ordered your rules so that the most-specific redirect rule is first, followed by the less-specific redirect, followed by the internal rewrite. This order prevents stacked or chained redirects, and prevents the redirects from "exposing" your index.php file.
Jim
[edited by: jdMorgan at 9:30 pm (utc) on Aug. 11, 2008]
Unfortunately when I modified my .htaccess file my non www domain, and all my internal pages gave me an error that said:
"The page isn't redirecting properly"
Firefox has detected that the server is redirecting the request for this address in a way that will never complete.
* This problem can sometimes be caused by disabling or refusing to accept cookies.
I think my CMS may be the reason this is not working.
Thanks again,
Jeremy