简体   繁体   English

在php中使用htaccess重写网址

[英]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. 现在,此页面的URL是property_list.php?propertytype_id=12 ,其中12是apartment的属性id 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 . 当用户单击此链接时,URL应该是sitename/apartments而不是显示property_list.php?propertytype_id=12 I've written the following code in my .htaccess file: 我在.htaccess文件中编写了以下代码:

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. 当我单击公寓时,那时它会在URL中显示公寓并列出所有公寓,但事实是它也在重定向主页和其他页面。

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 因此,当URL为/sitename/apartments将其重写为/property_list.php?propertytype_id=12

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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