【问题标题】:mod_rewrite adding trailing slashmod_rewrite 添加斜杠
【发布时间】:2015-02-06 23:12:37
【问题描述】:

我有很多 URL,例如 domain.com/something/

东西在我的新站点上domain.com/something 上的内容

现在首先我认为我通过执行以下重写规则将它放在了包里

RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /membersite.php [L]

嗯,这是成功的一半,我让 domain.com/something 和 domain.com/something/ 工作得很好,但现在的问题是我在 google 的眼里有重复的内容,一组 domain.com 上的内容/something AND another at domain.com/something/

所以我需要修改重写以在 domain.com/something/ 上对 domain.com/something 执行 301。

我还应该提到,任何其他不存在的目录或文件请求都应重定向到 domain.com 而不使用尾部斜杠。

这部分工作正常,但我想我应该提到页面 membersite.php 从不显示在 URL 中,而是 /something 是用户“个人资料”页面,这样每个人都可以看到全貌

【问题讨论】:

  • this link 有用吗?注意他在这个节点中如何使用“/?”,你可能需要一些没有“/”的东西

标签: php linux apache mod-rewrite


【解决方案1】:

我终于发现这是一个操作顺序的完整工作解决方案

RewriteEngine On
RewriteOptions inherit

RewriteBase /
RewriteRule ^index\.php$ - [L]

**RewriteRule ^(.+?)/$ $1 [R=301,L] // this part first strips the trailing slash**

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /membersite.php [L] //this part handles internally which file i'm loading from the server to process the request.

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2012-09-25
    • 1970-01-01
    • 1970-01-01
    • 2011-05-31
    • 1970-01-01
    • 2012-05-20
    • 2011-06-28
    • 2014-12-08
    相关资源
    最近更新 更多