Reputation: 1619
I am having a problem with rewritting the URL using .htaccess, When the URL is something that looks like that original url: http://www.example.com/page.php?id=1&name=test after rewrite: http://www.example.com/page-1-test it works fine
but the manager asked for hyphens instead of spaces so i did this
$name = str_replace(" ", "-", $name);
then i echo $page_name http://www.example.com/page.php?id=2&name=test-some-other-text
so it would look like this http://www.example.com/page-2-test-some-other-text
in the it takes 2-test-some-other-text as the id when i try to $_GET['id'];
and here is my rewrite rule in the .htaccess
RewriteRule page-(.*)-(.*)$ page.php?id=$1&name=$2
Upvotes: 1
Views: 2595
Reputation: 69937
Since the ID is a digit, try this rule:
RewriteRule page-([0-9]+)-(.*)$ page.php?id=$1&name=$2
It will only match digits for the ID and then end at the final dash instead of keeping on trying to greedy match.
Upvotes: 3