我试图找出如何在 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]