Forum Moderators: phranque
Whew. Now, here's my .htaccess, which doesn't work:
RewriteEngine on
RewriteRule ^/([^/]+)\.php(\?(.*))?$ /index.php?page=$1&$3 Thanks.
Save yourself lots of time... Do it now.
RewriteEngine on
#
RewriteCond $1 !=index
RewriteRule ^(.+)\.php$ /index.php?page=$1 [QSA,L]
EDIT: Here's my failed attempt:
RewriteCond %{QUERY_STRING} page=([^&;]*)
RewriteRule =index.php %1 [R] Re RTFM: Nah, I just went through what looked relevant to my situation. I don't think I could ever cram a whole manual in my brain without trying anything and probably asking a question. Although I have pounced for that myself before, and had I used Ctrl+F I might not have had such a big question.
[edited by: Jesdisciple at 3:15 am (utc) on June 11, 2009]
RewriteCond %{THE_REQUEST} ^[A-Z]+\ /index\.php\?([^&]*&)*page=([^&]+)(&[^\ ]*)*\ HTTP/
RewriteRule ^index\.php$ http://www.example.com/%2.php [R=301,L]
Note that the variable THE_REQUEST contains the exact client request line as seen (in quotes) in your raw server access log file.
Jim
Thanks much for the rules. Since I'm going through this whole URL-beautification, I decided to try taking the .php off the end in a redirect. But I ran into trouble with the feature that interprets foo the same as foo.php; is there any way to turn that off? Thanks again.
Regarding my semi-informed experimentation, note that I'm doing all this on my localhost. Hopefully I won't deploy any broken rules.
the feature that interprets foo the same as foo.php; is there any way to turn that off?
The feature is called MultiViews [httpd.apache.org], and you can turn it off in .htaccess or httpd.conf with the appropriate
Options directive. Unless you are actually using content negotiation, then it is best to turn off the feature as it can interfere with rewrites and opens you up to unnecessary duplicate-content issues.