htaccess Rerwite 规则冲突

问题描述

我必须重写相互冲突的规则。实际上,是第二条规则导致第一条规则不起作用,即使我换了位置。

artistmusic.PHP

From: http://www.example.com/artistmusic?slug=Ben
To: http://www.example.com/Ben/music

artistvideos.PHP

From: http://www.example.com/artistvideos?slug=Ben
To: http://www.example.com/Ben/videos

重写上述网址的规则。

RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^/]*)/([^/]*)$ /artist$2?address=$1 [L]

这应该像它应该的那样工作,直到我为下面的一组 URls 添加重写规则。

allsongs.PHP

From: http://www.example.com/allsongs?standard=popular&request=monthly
To: http://www.example.com/songs/popular/monthly

allartists.PHP

From: http://www.example.com/allartists?standard=popular&request=monthly
To: http://www.example.com/artists/popular/monthly

重写上面第二组的规则。

RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^/]*)/([^/]*)/([^/]*)$ /all$1?standard=$2&request=$3

上述规则有效,但会杀死第一个规则。 这是什么原因?谢谢。

解决方法

根据您显示的示例/尝试,请按以下方式创建您的 htaccess 规则文件。在测试您的网址之前,请务必清除浏览器缓存。

if ask_user == 'email':
    time.sleep(0.5)
    oscripts.email_script()


通用解决方案:如果您不想在新规则中对值进行硬编码,请尝试以下操作。确保使用以上或一次只使用 1 个。

RewriteEngine ON
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^songs/([^/]*)/([^/]*)/?$ allsongs.php?standard=$1&request=$2 [NC,L]

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^artists/([^/]*)/([^/]*)/?$ allartists.php?standard=$1&request=$2 [NC,L]

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^/]*)/(music|videos)/?$ artist$2.php?slug=$1 [QSA,NC,L]