.htaccess RewriteRule in subdirectory with PHP GET variables


.htaccess RewriteRule in subdirectory with PHP GET variables

我这里有两个关于.htaccess和PHP GET变量的问题。

基本上,我正在一个动漫网站上工作,我希望能够加载site.com/anime/AnimeName

现在,我把它当作site.com/anime/index.php?watch=AnimeName

我能够为我的用户配置文件执行此操作:

RewriteEngine On
RewriteCond %(REQUEST_FILENAME) !-f
RewriteCond %(REQUEST_FILENAME) !-d
RewriteRule ^(.*)$ /profile.php?username=$1 

我对 /anime/ 子目录中的.htaccess尝试了类似的方法,但我似乎无法让它工作。

我的第二个问题(不像主要问题那么大),是我想知道如何为 .htaccess 文件设置两个变量。

例如:我有剧集要site.com/anime/?watch=AnimeName&ep=Ep#

基本上,我想知道如何让它像这样: 第一集site.com/anime/AnimeName/1,第二集site.com/anime/AnimeName/2,依此类推。


更新:我在主.htaccess文件中执行此操作,它适用于用户名和动漫。
RewriteEngine On
RewriteCond %(REQUEST_FILENAME) !-f
RewriteCond %(REQUEST_FILENAME) !-d
RewriteRule ^u/(.*)$ /profile.php?username=$1 
RewriteRule ^a/(.*)$ /anime.php?watch=$1 

现在,我怎样才能做到这一点: 第 1 集site.com/a/AnimeName/1

我试过这个,但没有用: RewriteRule ^(.*)$/a/&ep=$1无论哪种方式,提前谢谢。

重写

条件应用于紧随其后的规则。所以你需要复制条件。

RewriteEngine On
RewriteCond %(REQUEST_FILENAME) !-f
RewriteCond %(REQUEST_FILENAME) !-d
RewriteRule ^u/(.*)$ /profile.php?username=$1 [L]
RewriteCond %(REQUEST_FILENAME) !-f
RewriteCond %(REQUEST_FILENAME) !-d
RewriteRule ^a/(.*)$ /anime.php?watch=$1 [L]

但是,如果/a//u/不是真正的子目录,则不需要条件。对于附加参数,您需要第三条规则:

RewriteEngine On
RewriteCond %(REQUEST_FILENAME) !-f
RewriteCond %(REQUEST_FILENAME) !-d
RewriteRule ^u/(.*)$ /profile.php?username=$1 [L]
RewriteCond %(REQUEST_FILENAME) !-f
RewriteCond %(REQUEST_FILENAME) !-d
RewriteRule ^a/([^/]+)$ /anime.php?watch=$1 [L]
RewriteCond %(REQUEST_FILENAME) !-f
RewriteCond %(REQUEST_FILENAME) !-d
RewriteRule ^a/([^/]+)/([0-9]+)$ /anime.php?watch=$1&ep=$2 [L]