简体   繁体   中英

url re writing using htaccess in php

I am working on property site and I want to rewrite some of the url in my site. There are some urls which list the property type-wise. In the footer there is a list of property types such as hotels, privatevilla, apartments....etc.

Now the url of this page is property_list.php?propertytype_id=12 where 12 is the property id of apartment. Instead of this url I'd given apartments.

When user clicks on this link then the url should be sitename/apartments instead of showing property_list.php?propertytype_id=12 . I've written the following code in my .htaccess file:

RewriteEngine On 
RewriteRule ^([a-zA-Z]+)?$ /property_list.php?propertytype_id=$1 [NC,L]

When I click on aprtments then at that time it is showing apartments in the url and listing all apartments but the thing is it is redirecting home page and other pages also.

How do I redirect only property type related pages?

So you basically want this?

RewriteEngine On 
RewriteRule ^apartments$ /property_list.php?propertytype_id=12 [NC,L]

Is this what you are looking for. So when the URL is /sitename/apartments rewrite it to /property_list.php?propertytype_id=12

RewriteEngine On
RewriteCond %{REQUEST_URI} /sitename/apartments [NC]
RewriteRule ^(.*)?$ /property_list.php?propertytype_id=12 [NC,L]

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM