【问题标题】:.htaccess 301 redirect to a new URL structure.htaccess 301 重定向到新的 URL 结构
【发布时间】:2012-03-23 18:32:39
【问题描述】:

我有以下 URL 结构,需要对新的 URL 结构进行 301 处理。

旧结构 /bla-bla-bla-400252596261.html

新结构 /listing/bla-bla-bla-400252596261.html

如何在 .htacces 中完成此操作?

编辑:我在根目录上确实有其他文件,但不是以 .html 结尾,因此它应该与该字符串匹配。因此,根目录中匹配 .html 扩展名的任何文件都应重定向到 /listing/bla-bla-bla-400252596261.html 页面。

【问题讨论】:

    标签: php apache .htaccess http-status-code-301


    【解决方案1】:

    试试这个:

    RewriteCond %{REQUEST_URI} ^/.*\.html$
    RewriteCond %{REQUEST_URI} !^/listing.*
    RewriteRule ^(.*\.html)$ /listing/$1 [R=301,QSA,L]
    

    更多例子here

    【讨论】:

    • 这很奇怪,因为它对我有用。我正在使用 Apache/2.2.21 (Win32) PHP/5.3.8 但是有时我的 Chrome 会缓存旧响应(同时 FF 工作正常)
    • 我在似乎是重定向循环的 URL 中得到了这个。 antique-furniture-online.com/listing/index.php/listing/…
    • 我没有看到我的条件和规则。你能告诉我.htaccess 的最终版本吗?请给我 2 个网址:第一个是您输入的内容,第二个是必须重定向用户的位置。
    猜你喜欢
    • 2013-01-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-06-17
    • 1970-01-01
    相关资源
    最近更新 更多