Mod_rewrite,引用另一个规则的异常除外


Mod_rewrite, with exception that refers to another rule

我想在我的页面上使用mod_rewrite,并且已经有了一些规则

现在我想重定向到artist.php?name=(PARAMETER),除非它与另一个规则匹配

目前,我在artist.php之前使用了一个"a/",因为我不知道如何解决这个问题所以如果我想看到艺术家"亚历克斯",我只需要键入domain.com/Alex,如果我想转到about页面,我只需键入domain.com/about(就像脸书或推特一样)

当然,我感谢的每一次改进

这是.htaccess

    RewriteEngine On 
RewriteBase / 
RewriteCond %{SCRIPT_FILENAME} !-f 
RewriteCond %{SCRIPT_FILENAME} !-d 
RewriteRule ^cover/([0-9]*)(s|m)?'.jpg$ /cover.php?id=$1&size=$2
RewriteRule ^dl/([^/]*)/([^/]*)$ /download.php?$1=$2
RewriteRule ^track/([^/]*)'.mp3$ /song.php?id=$1
RewriteRule ^my(/)([^/]*)$ /my.php?requested=$2
RewriteRule ^album/(.*)-([0-9]{0,6})$ /album.php?id=$2
RewriteRule ^a/([^/]*)$ /artist.php?name=$1
RewriteRule ^a/([^/]*)/music$ /music.php?name=$1
RewriteRule ^(artists|about|charts|contact|myprofile|editprofile|mymusic|uploadsongs|logout|genres)$ /$1.php
RewriteRule ^t$ /t.php
RewriteCond %{HTTP_REFERER} !^$
RewriteCond %{HTTP_REFERER} !^http://(www'.)?domain.com(/)?.*$ [NC]
RewriteRule .*'.(mp3)$ - [F,NC]
ErrorDocument 404 /errors/404.php

p.s.:很抱歉我的英语不好

您需要重新排列一些规则,并添加L标志,这样它们就不会意外应用:

RewriteEngine On 
RewriteBase / 
RewriteRule ^cover/([0-9]*)(s|m)?'.jpg$ /cover.php?id=$1&size=$2 [L]
RewriteRule ^dl/([^/]*)/([^/]*)$ /download.php?$1=$2 [L]
RewriteRule ^track/([^/]*)'.mp3$ /song.php?id=$1 [L]
RewriteRule ^my(/)([^/]*)$ /my.php?requested=$2 [L]
RewriteRule ^album/(.*)-([0-9]{0,6})$ /album.php?id=$2 [L]
RewriteRule ^a/([^/]*)$ /artist.php?name=$1 [L]
RewriteRule ^a/([^/]*)/music$ /music.php?name=$1 [L]
RewriteRule ^(artists|about|charts|contact|myprofile|editprofile|mymusic|uploadsongs|logout|genres|t)$ /$1.php [L]
RewriteCond %{HTTP_REFERER} !^$
RewriteCond %{HTTP_REFERER} !^http://(www'.)?domain.com(/)?.*$ [NC]
RewriteRule .*'.(mp3)$ - [F,NC]
# assume anything else is a username
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^/]+)$ /artist.php?name=$1 [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^/]+)/music$ /music.php?name=$1 [L]
ErrorDocument 404 /errors/404.php