Moonstone
Moonstone

Reputation: 121

mod_rewrite acting strange when moved to .htaccess

I had this rewrite rule in my httpd conf file:

RewriteRule (.*?)\.html $1.php?%{QUERY_STRING} [NC]

It worked fine. But when I place it into my .htaccess for that same virtual host, it's now returning the entire document path for $1 instead of the http host. All it needs to do is replace "html" with "php".

I obviously I don't understand how .htaccess works with rewrite rules.

Upvotes: 1

Views: 72

Answers (3)

Keyur Shah
Keyur Shah

Reputation: 11543

RewriteRule ^(.*)\.html$ $1.php [nc]

Upvotes: 0

Dale
Dale

Reputation: 1308

My eyes nearly bleed looking at that ugly thing...

 RewriteRule ^(.*).html?(.*)$ $1\.php?$2 [NC]

Upvotes: 0

Jon Lin
Jon Lin

Reputation: 143916

You need to add a leading slash in your rule's target:

RewriteRule (.*?)\.html /$1.php?%{QUERY_STRING} [NC]

Also, you can get rid of the ?%{QUERY_STRING} bit in the target as well. Query strings are automatically appended if there isn't a ?.

Upvotes: 1

Related Questions