Nick Nick - 15 days ago 6
PHP Question

htaccess rule for slash(/) in place of dash(-)

I have a htaccess rule as follows:

RewriteRule ^restaurant-([0-9_-]+)-([a-zA-Z0-9_-]+)-([a-zA-Z0-9_-]+)-menu$ rest_menu?&id=$1&area=$2&Name=$3


The url is as follows:
https://example.com/restaurant-3-place-restname-menu
.

But I want the url to be
https://example.com/restaurant-3-place-restname/menu
.

How do I change my htaccess rule so that it starts working.

Notice: the "- " before menu is replaced by "/".

Answer

Use this rule i am assuming rest_menu is a php file.

Options -Multiviews
RewriteEngine on
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^restaurant-([\d]+)-([\w-]+)-([\w-]+)/menu$ rest_menu.php?&id=$1&area=$2&Name=$3 [QSA,L]
Comments