更改URL但使用htaccess保持在同一页面上

时间:2012-11-30 19:26:43

标签: .htaccess url mod-rewrite

我有一个网址:

www.example.com/property-listings/united-states/colorado/denver/denver-co-office-space

我想留在上面的同一页面上,只需在地址栏中显示网址,如下所示:

www.example.com/property-listings/united-states/colorado/denver/office-space

如何使用htaccess和重写规则完成此操作?

2 个答案:

答案 0 :(得分:1)

如果我理解正确,请尝试编写如下规则:

RewriteEngine on
RewriteRule property-listings/united-states/colorado/denver/office-space  http://www.example.com/property-listings/united-states/colorado/denver/denver-co-office-space [L] 

行。你没有提供模式或提到有任何模式,所以我不得不猜测模式是否达到/ denver /子目录。试试这个:

RewriteEngine on
RewriteRule ^(property-listings/united-states/colorado/denver/)(office-space)/?$  $1denver-co-$2 [L]

答案 1 :(得分:0)

通过httpd.conf启用mod_rewrite和.htaccess,然后将此代码放在.htaccess目录下的DOCUMENT_ROOT中:

Options +FollowSymLinks -MultiViews
# Turn mod_rewrite on
RewriteEngine On
RewriteBase /

RewriteRule ^(property-listings/united-states/colorado)/(denver)/(office-space)/?$ $1/$2/$2-co-$3 [L,NC]