Search code examples
apache.htaccessmod-rewriteurl-rewritingfriendly-url

.htaccess to customize php url in folder


My php file is in this location: https://example.com/store/store.php?id=1

and I want to rewrite it as: https://example.com/store/store_name

I tried like below:

RewriteEngine On    # Turn on the rewriting engine
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule  ^([A-Za-z0-9_-]+)/?$  store.php?id=$1 [NC,L] #Handle page requests

But it is not working for me.


Solution

  • With your shown samples, please try following htaccess Rules file. Make sure to place your htaccess Rules file in folder where store folder is present, place it along side with store folder NOT inside it.

    Make sure to clear your browser cache before testing your URLs.

    RewriteEngine ON
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^store/(.*)/?$  store/store.php?id=$1 [QSA,NC,L]