2

How can I show following URL using .htaccess re-write rule with a non ? parameter?

Original URL
http://example.com/index.php?store=1

Desired URL 
http://example.com/1/

OR

Desired URL 
http://example.com/store/1

I am trying following code in .htaccess. What I am missing here?

RewriteEngine On
Options +Followsymlinks
RewriteCond %{REQUEST_FILENAME} !-f
rewriteRule ^store/(.+)\$ index.php?store=$1 [L]

my index.php file has this code

<?php
$storeid = $_GET['store'];
echo $storeid;
?>

What I am missing here?

1 Answer 1

1

You are escaping your end-of-string character, causing the expression to look for a literal $ sign so it never matches.

You need something like:

rewriteRule ^store/(.+)$ /index.php?store=$1 [L]
                       ^ no back-slash here

or if you want to make sure you only match numbers:

rewriteRule ^store/(\d+)$ /index.php?store=$1 [L]
Sign up to request clarification or add additional context in comments.

Comments

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.