我的.htaccess中有以下内容: Options + FollowSymLinks -MultiViews -Indexes
DirectorySlash Off
RewriteEngine On
RewriteBase /demotut/
# remove trailing slash
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{THE_REQUEST} \s(.+?)/+[?\s]
RewriteRule ^(.+?)/$ /demotut/$1 [R=301,L]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.+?)/(.*)$ $1.php [L]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.+?)$ $1.php [L]
这对我有用。代码假设执行以下操作:
1.如果请求进入:'host / demotut',则重定向到'host / demotut / index.php'
2.如果请求进入:'host / demotut / somefile',则重定向到'host / demotut / somefile.php'
3.如果请求来自:'host / demotut / somefile / and / urllike / vars',则重定向到'host / demotut / somefile.php /和/ urllike / vars'
网站根目录中的文件充当控制器。正如我所说,这确实有效,但重复的陈述让我感到困扰。
我玩[L]并评论出RewriteRule,但这是我让它工作的唯一方法。
无论如何要压缩这个吗?