很奇怪的.htaccess重写问题
我的 .htaccess 遇到了一个奇怪的问题
我有以下重写规则
#REMOVE TRAILING SLASH
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.+)/$ $1 [R=301,L]
#REWRITES
RewriteRule ^clients(/)?$ /views/pages/clients.php [L]
RewriteRule ^about(/)?$ /views/pages/about.php [L]
RewriteRule ^contact(/)?$ /views/pages/contact.php [L]
RewriteRule ^mobile(/)?$ /views/pages/tags.php?tag=mobile [L]
RewriteRule ^tablet(/)?$ /views/pages/tags.php?tag=tablet [L]
这些规则确实有效,但其中两个表现得很奇怪。
RewriteRule ^clients(/)?$ /views/pages/clients.php [L]
RewriteRule ^mobile(/)?$ /views/pages/tags.php?tag=mobile [L]
“客户端”重写规则始终带有尾部斜杠。
“mobile”重写规则重写为 http://www.mydomain.com/mobile/?tag =mobile
我需要解决这个问题,因为这些规则会导致不必要的重定向,从而影响我的 SEO 性能。
我觉得这很奇怪,因为它们与其他规则类似,而且效果很好。
另一个奇怪的事实:在我的本地主机上,重写表现得很好,在我的生产服务器上,它们表现得很奇怪
此外,我刚刚发现以下重写规则相应地起作用:
RewriteRule ^client(/)?$ /views/pages/clients.php [L]
这个不添加尾部斜杠,所以它必须是规则左侧的“客户”一词。
并且
这条规则也表现得很好
RewriteRule ^mobiles(/)?$ /views/pages/mobile.php [L]
所以,当我在规则的左侧使用“客户端”和“移动”时,它表现得很奇怪。当我使用“客户端”和“手机”时,它们表现得很好。
难道“clients”和“mobile”是保留词什么的?
I'm having a weird problem with my .htaccess
I have the following rewrite rules
#REMOVE TRAILING SLASH
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.+)/$ $1 [R=301,L]
#REWRITES
RewriteRule ^clients(/)?$ /views/pages/clients.php [L]
RewriteRule ^about(/)?$ /views/pages/about.php [L]
RewriteRule ^contact(/)?$ /views/pages/contact.php [L]
RewriteRule ^mobile(/)?$ /views/pages/tags.php?tag=mobile [L]
RewriteRule ^tablet(/)?$ /views/pages/tags.php?tag=tablet [L]
These rules do work BUT two of them act strangely.
RewriteRule ^clients(/)?$ /views/pages/clients.php [L]
RewriteRule ^mobile(/)?$ /views/pages/tags.php?tag=mobile [L]
The 'clients' rewrite rule always gets a trailing slash.
The 'mobile' rewrite rule rewrites to http://www.mydomain.com/mobile/?tag=mobile
I need to fix this problem because these rules result into unnecessary redirects which affect my SEO performance
I find this very strange because they are similiar to the other ones and they do just fine.
Another bizar fact: on my localhost the rewrites act just fine, it's on my production server they act strange
Also I just found out that the following rewrite rule acts accordingly:
RewriteRule ^client(/)?$ /views/pages/clients.php [L]
This one doesn't add a trailing slash, so it must be something with the word 'clients' in the left side of the rule.
AND
This rule acts fine also
RewriteRule ^mobiles(/)?$ /views/pages/mobile.php [L]
So, when I use 'clients' and 'mobile' in the left side of the rule, it acts strange. When I use 'client' and 'mobiles' they act just fine.
Can it be that 'clients' and 'mobile' are reserved words or something?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果生产服务器上有
clients
目录,这可能会导致您在重写时遇到问题。 (生产服务器上存在移动目录可能会出现类似的问题,但如果不亲自进行一些测试,我无法确定。)If you have a
clients
directory on the production server this could cause the issue that you are experiencing with that rewrite. (It's possible that there might be a similar problem with the existence of a mobile directory on the production server, but I cannot be certain without doing some testing myself.)