1

I want to create friendly url from

http://localhost/shop/categories.php?cat=asd --> http://localhost/shop/category/asd

but i always get Object not found Error 404 error from apache.

.htaccess:

RewriteEngine On
RewriteRule ^.+category/([a-zA-Z]+)$ /shop/categories.php?cat=$1 [QSA,L,NE]

categories.php

<?php 
echo $_GET["cat"]; 
?>

Tested with https://htaccess.madewithlove.be/

Output url: http://localhost/shop/categories.php?cat=asd (this url is working)

I've only 2 files in the folder shop:

Path:

C:\xampp\htdocs\shop

Files:

  • .htaccess
  • categories.php

More info:

  • mod_rewrite loaded (checked in phpinfo and httpd.conf)
  • AllowOverride All in httpd.conf and httpd.xampp.conf
X11
  • 332
  • 4
  • 19
  • 2
    Disable MultiViews - it often causes problems when what you are trying to rewrite (partially) matches the name of an actually existing file. – CBroe Jul 10 '18 at 11:26

1 Answers1

1

You should disable MultiViews option, which is enabled by default most of the time (see this post and my answer on this topic)

Here is how your /shop/.htaccess file should look like:

Options -MultiViews

RewriteEngine On
RewriteBase /shop/

RewriteRule ^category/([^/]+)$ categories.php?cat=$1 [L,NE]
Justin Iurman
  • 18,954
  • 3
  • 35
  • 54