Forum Moderators: phranque
I was hoping someone could point me in the right direction with what I have in my .htaccess file.
Based on jdMorgan's explanation of the rewrite [webmasterworld.com], I've got the following:
# Enable mod_rewrite, start rewrite engine
Options +FollowSymLinks
RewriteEngine on
#
# Internally rewrite search engine friendly static URL to dynamic filepath and query
RewriteRule ^(.*)view/(.*)/(.*)$ $1cgi-bin/view.pl?order=$2&orderdirection=$3
#
# Externally redirect client requests for old dynamic URLs to equivalent new static URLs
rewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /view\.pl\?order=([^&]+)&orderdirection=([^\ ]+)\ HTTP/
rewriteRule ^view\.pl$ http://www.example.com/view/%1/%2? [R=301,L]
These rules have www.example.com/view/DISK/ASC retrieving it's content from www.example.com/cgi-bin/view.pl?order=DISK&orderdirection=ASC correctly, but when the script is called directly it doesn't direct the user to the static page for the content.
Is there anything obvious that I've messed up with the .htaccess formatting?
I understand the "power" of regular expressions, but reading and writing .htaccess files feels like I'm on one of those code obsfucation contents...
My thanks in advanced to anyone providing assistance.
Your first rule is using terribly-inefficient patterns. Using ".*" multiple times in one pattern leads to horrible performance, because of the number of "trial" passes that the regex parser has to make to resolve them. It can also lead to very strange and unexpected matches, because ".*" matches anything.
I'd suggest re-coding that first rule as:
RewriteRule ^(.*)view/([^/]+)/([^/]+)$ $1cgi-bin/view.pl?order=$2&orderdirection=$3
Jim