Reputation: 474
I am trying to use mod_rewrite to keep only the query string in a url, and remove index.php?p=.
For example, this link
http://domain.com/index.php?p=page-name-with-dashes
Into
http://domain.com/page-name-with-dashes.html
All pages are loaded through the control script index.php and the query p=name, like this
<?php
$page = isset($_GET['p']) ? $_GET['p'] : 'home';
...
require_once 'content-' . $page . '.php';
...
?>
I have tried all variants below, but none works - some give 404 some give 500 errors.
#RewriteRule ^index.php?p=(.*) $1/
#RewriteRule ^([^/]+)/?$ /index.php?p=$1 [QSA,L]
#RewriteRule ^(.*)$ index.php?p=$1 [NC,L,QSA]
What am I doing wrong? I don't know much about htaccess rules, so forgive my newbie question.
Upvotes: 1
Views: 1075
Reputation: 3998
Try this:
RewriteRule ^(.*).html$ index.php?p=$1 [L]
But be aware that if you have multiple cases (for example some other type of url to rewrite) be careful with ordering of RewriteRules because you could easily override one with another...
Upvotes: 2