大多数RewriteRules工作正常,但有一些在其中有相同的单词并且没有进入正确的页面。
这是我的完整htaccess
Options +FollowSymLinks
RewriteEngine On
RewriteCond %{SCRIPT_FILENAME} !-f
RewriteCond %{SCRIPT_FILENAME} !-d
# Rewrites for main pages
RewriteRule home index.php
RewriteRule about-us about-us.php
RewriteRule business-advice business-advice.php
RewriteRule associates associates.php
RewriteRule become-an-associate associates-sign-up.php
RewriteRule blog blog.php
RewriteRule contact-us contact-us.php
RewriteRule log-in log-in.php
RewriteRule sign-up sign-up.php
问题在于两个相关链接。当我去[MYURL] /同事时,它工作正常,但如果我去[MYURL] /成为一个关联,它会将我带到正确的URL,但显示来自[MYURL] / associates
的内容有人有任何想法吗? 谢谢,
答案 0 :(得分:3)
RewriteRule
的模式是正则表达式,规则全部循环,直到URI停止变化。这意味着第一次,当您请求/become-an-associate
时,它会匹配并重写为/associates-sign-up.php
。然后,第二次,由于“/ 关联 -sign-up.php”,模式associates
的规则匹配。您需要添加边界检查(例如^
和$
)以及[L]
标记:
# Rewrites for main pages
RewriteRule ^home/?$ index.php [L]
RewriteRule ^about-us/?$ about-us.php [L]
RewriteRule ^business-advice/?$ business-advice.php [L]
RewriteRule ^associates/?$ associates.php [L]
RewriteRule ^become-an-associate/?$ associates-sign-up.php [L]
RewriteRule ^blog/?$ blog.php [L]
RewriteRule ^contact-us/?$ contact-us.php [L]
RewriteRule ^log-in/?$ log-in.php [L]
RewriteRule ^sign-up/?$ sign-up.php [L]