1

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.

1 Answer 1

2

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...

Sign up to request clarification or add additional context in comments.

2 Comments

With a small modification, it worked: RewriteRule ^(.*).html$ index.php?p=$1 [L]
I am sorry, I just copied one of lines from my last project .htaccess file. And did not modified it well, so I edited my answer now :)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.