Apache 在两个不同的文件上用相同的.htaccess重写规则

Apache 在两个不同的文件上用相同的.htaccess重写规则,apache,.htaccess,mod-rewrite,url-rewriting,friendly-url,Apache,.htaccess,Mod Rewrite,Url Rewriting,Friendly Url,我想制定一个重写规则,用于处理同一文件夹中包含的两个不同文件 localhost/nameOfUser will be applied to index.php localhost/nameOfUser?score=12 or localhost/nameOfUser/12 will be applied to post.php 我已经设法使第一个能用 RewriteEngine On RewriteRule ^(css|fonts)($|/) - [L] RewriteRule ^(php|

我想制定一个重写规则,用于处理同一文件夹中包含的两个不同文件

localhost/nameOfUser will be applied to index.php
localhost/nameOfUser?score=12 or localhost/nameOfUser/12 will be applied to post.php
我已经设法使第一个能用

RewriteEngine On
RewriteRule ^(css|fonts)($|/) - [L]
RewriteRule ^(php|avatars)($|/) - [L]
RewriteRule ^(user|post)($|/) - [L]
RewriteRule ^(.*)$ index.php?user=$1 [NC,QSA]
如果我加上

RewriteRule ^(.*)$ post.php?user=$1 [NC,QSA]
第二个开始工作,但第一个没有


甚至可以在同一个.htaccess文件中对两个不同的文件进行重写吗?

尝试一下以下规则:

RewriteEngine On
RewriteRule ^(css|fonts|php|avatars|user|post)($|/) - [L]
RewriteRule ^([^/]+)$ index.php?user=$1 [NC,QSA,L]
RewriteRule ^([^/]+)/([^/]+)$ post.php?user=$1&score=$2 [NC,QSA,L]
但是,如果希望
nameOfUser?score=12
正常工作,则需要将其修改为:

RewriteEngine On
RewriteRule ^(css|fonts|php|avatars|user|post)($|/) - [L]
RewriteCond %{QUERY_STRING} ^$
RewriteRule ^([^/]+)$ /index.php?user=$1 [NC,QSA,L]
RewriteCond %{QUERY_STRING} ^score=(.+)$
RewriteRule ^([^/]+) /post.php?user=$1&score=%1 [NC,L]

在localhost/user/score上不显示css。纯文本。@Mirakurun更新HTML以包含
标记。它应该出现在
标记的开头。