0

I have structure php url like:

example.com/category.php?cat=graphics-and-design

and I want to clean the url via a .htaccess rewrite rule to:

example.com/category/graphics-and-design

I tried the following code but still doesn't work:

RewriteRule ^([a-zA-Z0-9_-]*)\/(.*)$ category.php?cat=$1 [L,QSA]
1
  • Please show the complete contents of your .htaccess Commented Jan 24, 2018 at 15:05

1 Answer 1

1

If you don't want problems later with other rules, for example not being able to match example.com/project/foobar without it going to category.php?cat=foobar

Then I suggest you match the category as well:

RewriteRule ^category/(.*)$ category.php?cat=$1 [L,QSA]

If you still want to go down that route (pun intended), the problem is its passing the $1'st match:

example.com/category.php?cat=category

So instead pass match $2

RewriteRule ^([a-zA-Z0-9_-]*)/(.*)$ category.php?cat=$2 [L,QSA]
Sign up to request clarification or add additional context in comments.

3 Comments

I tried both none work for me. It generated 500 error.
You need to use RewriteEngine On and rewrite needs to be enabled.
Your need to check your apache error logs then, as i've tested both rules just to make sure, and no 500's

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.