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
1
  • 2
    Disable MultiViews - it often causes problems when what you are trying to rewrite (partially) matches the name of an actually existing file. Commented Jul 10, 2018 at 11:26

1 Answer 1

0

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]
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.