.htaccess多次重写规则覆盖问题

时间:2017-07-05 17:01:48

标签: apache .htaccess mod-rewrite url-rewriting

首先,我不是.htaccess和Rewrite Rules的专家。

我有一些重写规则,所有这些规则都在运行。 当我添加新规则;它覆盖其他规则并重定向错误页面

RewriteRule ^([^/]+)/([0-9]+)/?$ article-list.php?link=$1&page=$2 [L,QSA,NC]
RewriteRule ^([^/]+)/?$ article-list.php?link=$1 [L,QSA]
RewriteRule ^videolar/$ video-list.php?page=$1 [L,QSA]

当我尝试点击网址www.mywebpage.com/videolar/1

不幸的是,它正在重定向到article-list.php页。

有什么方法可以解决这个问题吗?

任何帮助都会大大增加。

Full Htaccess;

Options +FollowSymLinks -MultiViews

RewriteEngine On
RewriteBase /

RewriteRule ^uye-ol/?$ register.php [L,NC]
RewriteRule ^uye-girisi/?$ login.php [L,NC]
RewriteRule ^sifremi-unuttum/?$ forget-password.php [L,NC]
RewriteRule ^yazarlar/?$ writer-list.php [L,NC]
RewriteRule ^videolar/?$ video-list.php?page=$1 [L,QSA]
RewriteRule ^foto-galeri/?$ gallery-list.php [L,NC]
RewriteRule ^biyografiler/?$ biography-list.php [L,NC]
RewriteRule ^yazar/([^/]+)-([^/]+)/([^/]+)-([^/]+)/?$ writer-article.php?link=$1&writerId=$2&articleLink=$3&writerArticleId=$4 [L,QSA]
RewriteRule ^yazar/([^/]+)-([0-9]+)/([0-9]+)/?$ writer-article-list.php?link=$1&writerId=$2&page=$3 [L,QSA]
RewriteRule ^foto-galeri/([0-9]+)/?$ gallery-list.php?page=$1 [L,QSA]
RewriteRule ^foto-galeri/([^/]+)-([^/]+)/([^/]+)/?$ gallery-photo.php?link=$1&i=$2&photo=$3 [L,QSA]
RewriteRule ^videolar/([^/]+)-([^/]+)/?$ video.php?link=$1&i=$2 [L,QSA]
RewriteRule ^haber/([^/]+)-([^/]+)/?$ article.php?link=$1&i=$2 [L,QSA]
RewriteRule ^biyografi/([^/]+)-([^/]+)/?$ biography.php?link=$1&bioId=$2 [L,QSA]
RewriteRule ^([^/]+)/([0-9]+)/?$ article-list.php?link=$1&page=$2 [L,QSA,NC]
RewriteRule ^([^/]+)/?$ article-list.php?link=$1 [L,QSA]
RewriteRule ^videolar/$ video-list.php?page=$1 [L,QSA]

1 个答案:

答案 0 :(得分:1)

RewriteRule ^([^/]+)/([0-9]+)/?$ article-list.php?link=$1&page=$2 [L,QSA,NC]
RewriteRule ^([^/]+)/?$ article-list.php?link=$1 [L,QSA]
RewriteRule ^videolar/$ video-list.php?page=$1 [L,QSA]

您需要更改这些指令的顺序,以便最具体的指令。就目前而言,第一个指令与URL /videolar/1匹配,因此"赢得"。

但是,您赢得的最后一条规则也不匹配/videolar/1(它只匹配/videolar/),因此需要修改模式。

请尝试以下内容:

RewriteRule ^videolar/([0-9]+)/?$ video-list.php?page=$1 [L,QSA]
RewriteRule ^([^/]+)/([0-9]+)/?$ article-list.php?link=$1&page=$2 [L,QSA,NC]
RewriteRule ^([^/]+)/?$ article-list.php?link=$1 [L,QSA]