我正在尝试编写一个基本上执行此操作的htaccess文件:
if(requested file == "some-file.php" || requested file == "some-file2.php" || requested file == "some-file3.php")
then Rewrite to redirector.php?uri=some-file.php <- substitute requested file without passing any parameters
else
// existing rewrite conditions from silverstripe
RewriteCond %{REQUEST_URI} ^(.*)$
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule .* sapphire/main.php?url=%1&%{QUERY_STRING} [L]
使用htaccess可以吗?
答案 0 :(得分:0)
我认为您需要做的就是将3个唯一请求的文件放在顶部3 RewriteRule
s,高于RewriteCond
的位置:
RewriteEngine On
RewriteRule /(some-file.php) http://test.dev/redirector.php?uri=$1 [L]
RewriteRule /(some-file2.php) http://test.dev/redirector.php?uri=$1 [L]
RewriteRule /(some-file3.php) http://test.dev/redirector.php?uri=$1 [L]
// rest of Rewrite Stuff
答案 1 :(得分:0)
尝试此规则:
RewriteRule ^(some-file\.php|some-file2\.php|some-file3\.php)$ redirector.php?uri=$1
答案 2 :(得分:0)
这是你的解决方案:
# if files are know, redirect and stop:
RewriteRule ^(some-file|some-file2|some-file3)\.php$ redirector.php?uri=$1.php [QSA,L]
# files that were not known go here:
# existing rewrite conditions from silverstripe
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule .* sapphire/main.php?url=%1&%{QUERY_STRING} [L]
诺塔: 我删除了:
RewriteCond %{REQUEST_URI} ^(.*)$
哪个没用。如果你想测试“非空”,那应该是:
RewriteCond %{REQUEST_URI} !^$
奥利弗