问题
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