【发布时间】:2010-10-04 16:27:35
【问题描述】:
我正在尝试在我的网站上创建干净的 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]
谢谢!
【问题讨论】:
-
欢迎堆栈溢出。感谢您清楚地表达您的问题,提供代码,并展示哪些有效,哪些无效。如果您的 apache 日志中有有用的信息,请也发布。有时,当您看到日志时,重定向问题会变得更加明显。
-
很遗憾,我无法获得此类信息。
标签: apache .htaccess url-rewriting