清理URL重定向循环

prn*_*leo 9 apache .htaccess url-rewriting

我正在尝试在我的网站上创建干净的URL.现在我成功配置了apache,所以像mysite.com/page这样的每个请求都能正常工作.但我也希望将mysite.com/page.php的请求重定向到mysite.com/page.我在.htaccess中设置环境变量来检查我是否已被重定向以防止循环,但我仍然得到它们......这是.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]
Run Code Online (Sandbox Code Playgroud)

谢谢!

Mic*_*ren 14

如果请求已被重定向一次(ref),请将此规则添加到现有重写规则之上以停止重定向:

RewriteCond %{ENV:REDIRECT_STATUS} 200
RewriteRule .* - [L]
Run Code Online (Sandbox Code Playgroud)