Forum Moderators: phranque
I am editing the httpd.conf file on my sme server
running 2.0.52 apache
here is part of the file that is relevant
RewriteEngine on
RewriteCond %{REQUEST_METHOD} ^(TRACEŠTRACK)
RewriteRule .* - [F]
##www.example.com/index.php to redirect to www.example.com
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /([^/]+/)*index\.php\ HTTP/
RewriteRule ^(([^/]+/)*)index\.php$ http://www.example.com/$1 [R=301,L]
##example.com is redirected to www.example.com
RewriteCond %{HTTP_HOST} ^example\.com
RewriteRule (.*) http://www.example.com$1 [R=301,L]
example.com is redirected to www.example.com and is working fine
but I cannot get www.example.com/index.php to redirect to www.example.com
I am a newbie to rewrites and am in the middle of the second day trying to solve this problem. I have studied many examples and feel that this should work.
Any pointers to why it's not working would be greatfully appreciated
thanks very much
Dickie
The URL-path "seen" by RewriteRule differs in these contexts, so the patterns must be adjusted:
RewriteEngine on
#
## Deny HTTP TRACE and TRACK methods
RewriteCond %{REQUEST_METHOD} ^(TRACEŠTRACK)
RewriteRule .* - [F]
#
## Externally redirect /<any-directory>/index.php to www.example.com/<any-directory>/
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /([^/]+/)*index\.php\ HTTP/
RewriteRule [b]^/([/b]([^/]+/)*)index\.php$ http://www.example.com/$1 [R=301,L]
#
## Externally redirect all non-canonical example.com hostnames to canonical www.example.com hostname
RewriteCond %{HTTP_HOST} example\.com [NC]
RewriteCond %{HTTP_HOST} !=www.example.com
RewriteRule [b]^/([/b].*)$ http://www.example.co[b]m/$[/b]1 [R=301,L]
The "!=www.example.com" pattern is identical to the fully-anchored regex pattern "!^www\.example\.com$" but uses a simple exact-match string compare instead of regular expressions. This is a slightly more efficient way to look for exact matches.
Important: Replace all broken pipe "Š" characters with solid pipes before use; Posting on this forum modifies the pipe characters.
Jim