【问题标题】:Change URL but stay on the same page using htaccess使用 htaccess 更改 URL 但留在同一页面上
【发布时间】:2012-11-30 19:26:42
【问题描述】:

我有一个网址:

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 和 rewrite 规则完成此操作?

【问题讨论】:

    标签: .htaccess url mod-rewrite


    【解决方案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]
    

    【讨论】:

      【解决方案2】:

      通过httpd.conf启用mod_rewrite和.htaccess,然后把这段代码放到你.htaccessDOCUMENT_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]
      

      【讨论】:

      • 尝试了上面的代码,但是似乎没有执行重写规则。我知道我启用了 mod_rewrite,因为当我将随机垃圾添加到我的 .htaccess 时,我收到 500 错误。什么可能导致重写规则不起作用?
      猜你喜欢
      • 2016-07-20
      • 1970-01-01
      • 1970-01-01
      • 2012-11-10
      • 1970-01-01
      • 2018-06-10
      • 1970-01-01
      • 2020-09-17
      • 2011-04-27
      相关资源
      最近更新 更多