重定向循环用简单的htaccess的规则

编程入门 行业动态 更新时间:2024-10-21 10:10:46
本文介绍了重定向循环用简单的htaccess的规则的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我一直在拉我的空出了这一点。它的工作服务器迁移之前!

I have been pulling my air out over this. It worked before the server migration!

好了,所以基本上它是像这样简单:

Ok so basically it's as simple as this:

我有我想要查看通过重写规则使用搜索引擎友好的URL的内容的PHP文件。

I have a .php file that I want to view the content of using a SEO friendly URL via a ReWrite rule.

另外要canonicalise和prevent重复的内容我想301的.php版本的搜索引擎友好的版本。

Also to canonicalise and to prevent duplicate content I want to 301 the .php version to the SEO friendly version.

这是我使用,并一直工作到现在,在新服务器上:

This is what I used and has always worked till now on the new server:

RewriteRule ^friendly-url/$ friendly-url.php [L,NC] RewriteRule ^friendly-url.php$ /friendly-url/$1 [R=301,L]

然而灾难袭击了,现在它会导致重定向循环。

However disaster has struck and now it causes a redirect loop.

从逻辑上讲,我只能假设,在这个版本的Apache被绊倒了,因为它是看到脚本正在运行的的.php版本,所以它会试图再次重定向。

Logically I can only assume that in this version of Apache it is tripping up as it's seeing that the script being run is the .php version and so it tries the redirect again.

我怎么能重新工作,这使得它的工作?还是有一个配置,我需要在南国切换?

How can I re-work this to make it work? Or is there a config I need to switch in WHM?

谢谢!

推荐答案

这是怎样的的.htaccess 应该是这样的:

This is how your .htaccess should look like:

Options +FollowSymLinks -MultiViews RewriteEngine On RewriteBase / # To externally redirect /friendly-url.php to /friendly-url/ RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s/+(friendly-url)\.php [NC] RewriteRule ^ /%1/? [R=302,L] ## To internally redirect /anything/ to /anything.php RewriteCond %{REQUEST_FILENAME} !-d RewriteCond %{DOCUMENT_ROOT}/$1\.php -f RewriteRule ^(.+?)/$ $1.php [L]

请注意我如何使用 R = 302 ,因为我不希望规则缓存在我的浏览器,直到我确认其预期的工作,那么,一旦我可以确认它按预期工作,我从 R = 302 切换到 R = 301 。

Note how I am using R=302, because I don't want the rule to cache on my browser until I confirm its working as expected, then, once I can confirm its working as expected I switch from R=302 to R=301.

请记住,您还可能已经由于您使用的缓存从previous尝试 R = 301 ,让你更好地试图从访问不同的浏览器你已经使用只是为了确保它的工作。

Keep in mind you may have also been cached from previous attempts since you're using R=301, so you better of trying to access it from a different browser you have used just to make sure its working.

然而灾难袭击了,现在它会导致重定向循环。

However disaster has struck and now it causes a redirect loop.

这会导致一个重定向循环,因为您重定向到自己,我的code不同的是,我抓住的请求,并从那里重定向PHP文件,使之友好,然后使用内部重定向。

It causes a redirect loop because your redirecting it to itself, the different on my code is that I capture the request, and redirect the php files from there to make it friendly and then use the internal redirect.

更多推荐

重定向循环用简单的htaccess的规则

本文发布于:2023-11-01 18:16:44,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1550057.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:重定向   规则   简单   htaccess

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!