清洁URL重定向循环 [英] Clean URL Redirect Loop

查看:252
本文介绍了清洁URL重定向循环的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在我的网站上创建干净的网址。现在,我成功地配置Apache等等之类的 mysite.com/page 的每一个请求会工作。但我也想,对于 mysite.com/page.php 的将被重定向到的 mysite.com/page 的请求。我在.htaccess中设置环境变量来检查,如果我已经被重定向到prevent循环,但我还是让他们... 这里的htaccess的:

I'm trying to create clean URLs on my website. Now I succeeded in configuring apache so every request like mysite.com/page will work. But I also want that requests for mysite.com/page.php will be redirected to mysite.com/page. I've set environment variable in .htaccess to check if i already been redirected to prevent loops, but i still get them... Here's the .htaccess:

<IfModule mod_rewrite.c>
Options +FollowSymlinks

RewriteEngine On
RewriteBase /

# set the variable
RewriteRule ^$ - [L]
RewriteRule ^(.*)$ $1 [E=REWROTE:0]

# this works fine
# make mysite.com/page work and set REWROTE variable to 1
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.php -f
RewriteRule ^(.*)$ $1.php [L,E=REWROTE:1]

# but if i enable this, i get redirected and then stuck in a loop
# redirect mysite.com/page.php to mysite.com/page , but only if REWROTE not 1
#RewriteCond %{ENV:REWROTE} !^1$
#RewriteRule ^(.*)\.php$ $1 [R=301,L]

谢谢!

推荐答案

添加上述现有的重写规则此规则,以阻止该请求是否已经被重定向一旦重定向(<一href="http://www.askapache.com/htaccess/mod_rewrite-tips-and-tricks.html#fix-infinite-loop-redirects">ref):

Add this rule above your existing rewrite rules to stop redirecting if the request has already been redirected once (ref):

RewriteCond %{ENV:REDIRECT_STATUS} 200
RewriteRule .* - [L]

这篇关于清洁URL重定向循环的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆