1

我正在尝试编写一个基本上执行此操作的 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吗?

4

3 回答 3

0

我认为您需要做的就是将 3 个唯一请求的文件作为 3 RewriteRules 放在顶部,在这些文件之上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
于 2009-10-22T23:38:00.583 回答
0

试试这个规则:

RewriteRule ^(some-file\.php|some-file2\.php|some-file3\.php)$ redirector.php?uri=$1
于 2009-10-23T09:40:06.807 回答
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} !^$

奥利维尔

于 2011-11-18T09:11:30.707 回答