1

I would like to clear my url by using RewriteRule at .htacces.

I would like to change /product/detail.php?id=red-shirt to something like this /product/red-shirt.

I tried to use this RewriteRule ^/?product/([^/d]+)/?$ /product/detail.php?id=$1 [L,QSA] but it does not work.

Martin Štefek
  • 358
  • 4
  • 12
  • Shouldn't that be `\d` instead of `/d`? – Aleks G Jan 11 '15 at 13:15
  • Please **edit** your question and define "does not work". Do you get an error (404, 500), what is the error in the server log if any is generated, what url do you end up with in the browser. Does your computer explode in a cloud of unicorns when you go to that url? Also please note that there is a format as code button in the editor (button with `{}` on it). Select your code and click that button. – Sumurai8 Jan 11 '15 at 13:15
  • In addition to @Sumurai8 's comment, enable rewrite log and check its content. – Aleks G Jan 11 '15 at 13:16

2 Answers2

1

You're getting 404 because your regex is wrong. Use this rule to fix this:

# If the request is not for a valid directory
RewriteCond %{REQUEST_FILENAME} !-d
# If the request is not for a valid file
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^product/([^/]+)/?$ /product/detail.php?id=$1 [L,NC,QSA]
anubhava
  • 761,203
  • 64
  • 569
  • 643
0

I will all the time get 404 Error. If I change /d to \d I will get interal server error 500

Martin Štefek
  • 358
  • 4
  • 12