我试图找出如何在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有一些重定向...
但我不希望我的网站链接中显示网址参数 ...所以我猜它确实需要htaccess。
我必须承认,我读到了htaccess的东西,它正好超越了我的头脑,因为没有人以我理解的方式解释过。
任何帮助将不胜感激。
EDIT :: ///
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]
答案 0 :(得分:0)
你可以拥有
RewriteRule ^prefix/games/(.*)$ prefix/protected/files/$1 [L]
将所有 http://localhost/prefix/games/userid/game-name
链接重定向至 http://localhost/prefix/protected/files/userid/game-name
或者,你可以
RewriteCond %{QUERY_STRING} user=(.*)&title=(.*)$
RewriteRule ^prefix/games/index.php$ /prefix/protected/files/%1/%2? [L]
将所有链接: http://localhost/prefix/games/index.php?user=userid&title=game-name
移至 http://localhost/prefix/protected/files/userid/game-name