Forum Moderators: phranque
Jim
i'm a but confused at what i would have to do, because it's only *.php i want to send over to *.html, i don't have a /blabla.html i need to redirect.
i don't know where to begin with the example of:
# Externally redirect direct browser requests for /topic.html to /topic
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /topic\.html
RewriteRule ^topic\.html$ http://www.example.com/topic [R=301,L]
#
# Internally rewrite requests for /topic to /topic.html
RewriteRule ^topic$ /topic.html [L]
# Rewrite (only) direct browser requests for php files to nonexistent path to generate a 404
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /[^.?]+\.php
RewriteRule \.php /some_page_that_does_not_exist [L]
An alternative might be:
# Retrun 410-Gone for (only) direct browser requests for php files
RewriteCond %{HTTP_HOST} .
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /[^.?]+\.php
RewriteRule \.php - [G]
It's likely that your bad experience with 301s was due to the fact that it's easy to create a loop if the 'special' technique shown here to detect a direct browser request is not used. If you have any search engine listings of php pages that have usable PageRank, then go ahead and redirect them:
# Externally redirect direct browser requests for /topic.html to /topic
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /[^.?]+\.php
RewriteRule ^([^.]+)\.php$ http://www.example.com/$1.html [R=301,L]
Jim
i have added:
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /[^.?]+\.php
RewriteRule ^([^.]+)\.php$ [mysite.com...] [R=301,L]
now, my question is:
does it matter how i have my htaccess arranged?
this rewrites all of my product categories from strings to plain html:
RewriteEngine on
RewriteBase /
RewriteRule ^([^/]*)\.html$ $1.php?%{QUERY_STRING} [NC]
RewriteRule ^/?(product)/([^/]*)\.html$ product_info.php?products_id=$2&%{QUERY_STRING} [NC]
etc, etc.
does it matter where i position your edit? currently, i have it beneath the product_info.php?products_id=$2&%{QUERY_STRING} [NC]
RewriteRule ^([^/]*)\.html$ $1.php?%{QUERY_STRING} [NC]
RewriteRule ^([^.]+)\.html$ $1.php [NC]
The note about the negative match again applies to the rule that follows that one.
Jim