我有一个网址:
www.example.com/property-listings/united-states/colorado/denver/denver-co-office-space
我想留在上面的同一页面上,但只需在地址栏中显示 URL,如下所示:
www.example.com/property-listings/united-states/colorado/denver/office-space
如何使用 htaccess 和重写规则完成此操作?
我有一个网址:
www.example.com/property-listings/united-states/colorado/denver/denver-co-office-space
我想留在上面的同一页面上,但只需在地址栏中显示 URL,如下所示:
www.example.com/property-listings/united-states/colorado/denver/office-space
如何使用 htaccess 和重写规则完成此操作?
如果我理解正确,请尝试编写如下规则:
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]
通过启用 mod_rewrite 和 .htaccess httpd.conf
,然后将此代码放在您.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]