多个复杂的 .htaccess RewriteRules

multiple complex .htaccess RewriteRules

我需要帮助在我的 .htaccess 文件中设置 RewriteRules。我需要先检查是否存在任何现有文件,然后进行一些自定义重写,如果其中任何一个不匹配,则将其重写为 index.php.

我当前的 .htaccess,位于文档根目录中,文件如下所示:

RewriteEngine On

RewriteBase /

# Don't rewrite existing files
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-l

# Custom rewrites
# TODO: Don't know how to make these work
# RewriteRule ^/css/style\.css$  /css/style.css.php [L,NC,QSA]
# RewriteRule ^/js/config\.js$   /js/config.js.php [L,NC,QSA]
# RewriteRule ^/js/post\.js$     /js/post.js.php [L,NC,QSA]

# If any of the above don't match hand it to index.php
RewriteRule ^(.+)$ index.php [QSA,L]

php_value upload_max_filesize 10485760
php_value post_max_size 10485760

提前致谢!

这样说:

RewriteEngine On
RewriteBase /

# Custom rewrite rule
RewriteRule ^(?:css/style\.css|js/(?:config|post)\.js)$ [=10=].php [L,NC]

# Don't rewrite existing files
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-l
# If any of the above don't match hand it to index.php
RewriteRule . index.php [L]

这是新规则:

RewriteRule ^(?:css/style\.css|js/(?:config|post)\.js)$ [=11=].php [L,NC]

匹配 /css/style.css/js/config.js/js/post.js 并在这些 URI 的末尾添加 .php[=16=] 是完整匹配的反向引用。