HTACCESS我如何与我的代码争夺以获得正确的重定向

时间:2012-06-14 20:03:30

标签: php .htaccess url mod-rewrite

我的HTACCESS文件目前看起来像这样:

RewriteEngine On        
RewriteBase /

# stop directory listings
#Options -Indexes 

#stops htaccess views
#<Files .htaccess>
#order allow,deny
#deny from all
#</Files>        

# redirect game folders     
RewriteRule ^games/([^/]+)/([^/]+) games.php?author=$1&slug=$2 [L]   

# redirect edit     
RewriteRule ^protected/edit-game/([^/]+)/([^/]+) protected/edit-game.php?author=$1&slug=$2 [L] 
RewriteRule ^admin/edit-game/([^/]+)/([^/]+) admin/edit-game.php?author=$1&slug=$2 [L]

# redirect view     
RewriteRule ^protected/view-game/([^/]+)/([^/]+) protected/view-game.php?author=$1&slug=$2 [L]   

# redirect user
RewriteRule ^page/([^/]+) user.php?user=$1 [L]  

# remove .php; use THE_REQUEST to prevent infinite loops
RewriteCond %{THE_REQUEST} ^GET\ (.*)\.php\ HTTP
RewriteRule (.*)\.php$ $1 [R=301]     

# remove index
RewriteRule (.*)/index$ $1/ [R=301]

# remove slash if not directory
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} /$
RewriteRule (.*)/ $1 [R=301]

# add .php to access file, but don't redirect
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteCond %{REQUEST_URI} !/$
RewriteRule (.*) $1\.php [L]   

ErrorDocument 404 /error-404.php

当有人去www.domain.com/im-a-page-in-database

时,我有了新的要求。

它转到我的page.php,抓住隐藏的'slug' - &gt; 'im-a-page-in-database'并查询返回该特定页面对象的数据库。

事情是,如果我在我的HTACCESS文件中添加如下内容:

# redirect pages/posts 
RewriteRule ^([^/]+) page.php?slug=$1 [L]     

它只是覆盖所有以前可能成功的重写并显示我的page.php,无论它放在htaccess文件中的哪个位置?我认为L意味着如果规则得到承认......它应该停止尝试做事。所以,如果我把我的新行放在我的所有重定向下,它应该最后进行页面检查..但是没有:(

有什么想法吗?

1 个答案:

答案 0 :(得分:0)

也许是因为你的301-Redirect?浏览器会缓存这些重定向,因此您必须尝试使用​​其他浏览器或清除缓存。