【发布时间】:2012-05-05 15:04:31
【问题描述】:
我正在尝试找出如何在 htaccess 中做这样的事情:
#This address links to a place that does not exist
localhost/prefix/games/userid/game-name
默默地(我猜是[L])重定向到
#This folder has an index.php, so we're good!
localhost/prefix/protected/files/userid/game-name/
我知道我可以有一个链接:
localhost/prefix/games/index.php?user=userid&title=game-name
只需在 index.php 中添加一些重定向...
但我不希望 url 参数在我网站上的链接中可见...所以我想它确实需要是 htaccess。
我必须承认,我读过 htaccess 的内容,但它让我无法理解,因为没有人以我理解的方式解释。
任何帮助将不胜感激。
编辑::///
RewriteEngine On
RewriteBase /prefix
# stop directory listings
Options -Indexes
#stops htaccess views
<Files .htaccess>
order allow,deny
deny from all
</Files>
# 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]
# redirect game folders
RewriteRule ^prefix/games/(.*)$ /prefix/protected/files/$1/ [R=301]
【问题讨论】:
标签: .htaccess url redirect parameters