简体   繁体   English

mod_rewrite添加斜杠

[英]mod_rewrite adding trailing slash

I have a lot of URL's like domain.com/something/ <-notice the trailing slash that are indexed with google thanks to a previous developer implementing wordpress which now means i'm stuck trying to make a lot of highly SEO ranked pages do a redirect on the new website that will replace the wordpress website and needs to have the same URL's. 我有很多URL,例如domain.com/something/ <-请注意,由于以前的开发人员实施了wordpress,因此Google用索引将其作为斜杠,这意味着我一直在努力使很多SEO排名靠前的页面重定向到将替换wordpress网站且需要具有相同URL的新网站。

The things is on my new site I have a page that functions as a catchall and does a database query to check to see if we have a members name that exists(the /something in the example URL above), and displays the content at domain.com/something 事情在我的新站点上,我有一个页面可以用作处理程序,并进行数据库查询以检查是否存在成员名称(上面示例URL中的/ something),并在域中显示内容。 .com / something

Now first I thought I had this in the bag by doing the following rewrite rule(s) 现在首先我想通过执行以下重写规则将其保存在书包中

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

Well this was half the battle I got domain.com/something AND domain.com/something/ working great but now the issue with this is I have duplicate content in the eyes of google one set of the content at domain.com/something AND another at domain.com/something/ 好吧,这是我让domain.com/something AND domain.com/something/正常工作的一半,但是现在的问题是,我在Google眼里有重复的内容,domain.com / something上的一组内容又另一个在domain.com/something/

So I need to modify the rewrite to do a 301 on domain.com/something/ to domain.com/something. 因此,我需要修改重写以在domain.com/something/上将301更改为domain.com/something。

I should also mention that any other non-existent directories or file requests should be redirected to domain.com without the trailing slash. 我还应该提到,任何其他不存在的目录或文件请求都应重定向到domain.com,且不要在末尾加反斜杠。

Also this part is working fine but figured I should mention the page membersite.php never shows in the URL but instead /something which is the users "profile" page, just so everyone see the whole picture 另外,这部分工作正常,但我想指出的是页面memberite.php从未在URL中显示,而是/ something这是用户的“个人资料”页面,所以每个人都可以看到整个图片

Full working solution which i finally figured out it's an order of operations 完整的解决方案,我终于发现这是一个操作顺序

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.

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM