only top condition is working not others for url rewriting?

余生颓废 提交于 2019-12-24 11:00:53

问题


This is my htaccess code for url-rewriting. I have a problem here.

Options +FollowSymLinks -MultiViews -Indexes

<IfModule mod_rewrite.c>

DirectoryIndex index.php

RewriteEngine on 

RewriteCond %{REQUEST_FILENAME} !-d 
RewriteCond %{REQUEST_FILENAME}\.php -f 
RewriteRule ^(.*)$ $1.php

ErrorDocument 404 404error.php

RewriteEngine On

RewriteRule ^([A-Za-z0-9-]+)?$ specification.php?url=$1

RewriteRule ^([A-Za-z0-9-]+)?$ news.php?url=$1

RewriteRule ^([A-Za-z0-9-]+)?$ social.php?url=$1

</IfModule>

here are three pages with different data. When I click for spcification.php page data then it will redirect me on same page but if my this code is above from this then it will redirect me to on news.php.

RewriteRule ^([A-Za-z0-9-]+)?$ news.php?url=$1

only top condition work not others.


回答1:


From what I know you cannot use same rule for multiple conditions like this

RewriteRule ^([A-Za-z0-9-]+)?$ specification.php?url=$1

When first rule matched it stop searching for same condition, instead you have to use

RewriteRule ^specification/([A-Za-z0-9-]+)?$ specification.php?url=$1 [L]
RewriteRule ^news/([A-Za-z0-9-]+)?$ news.php?url=$1 [L]

Your original url will look like this domain.com/news/value.



来源:https://stackoverflow.com/questions/42502040/only-top-condition-is-working-not-others-for-url-rewriting

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!