在我的.htaccess文件中,a有很多对seo友好的链接。现在我试图将搜索引擎优化友好链接应用到一个子文件夹。(这些文件在“拉脱维亚”文件夹中)
以下是.htaccess文件的内容:
RewriteEngine on
ErrorDocument 404 /404.php
RewriteCond %{HTTPS} off
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI}
# DO NOT REMOVE THIS LINE AND THE LINES ABOVE SSL_REDIRECT:SSL_REDIRECT
RewriteRule ^latvia/2017/tournaments latvia/2017-lv-calendar.php [NC]
RewriteRule ^latvia/adults/tournaments latvia/lvt_adults.php [NC]
RewriteRule ^latvia/juniors/tournaments latvia/lvt_juniors.php [NC]
RewriteRule ^latvia/federation latvia/lv-federation.php [NC]
RewriteRule ^latvia/juniors/rankings latvia/lvj-rankings.php [NC]
RewriteRule ^latvia/adults/rankings latvia/lva-rankings.php [NC]
RewriteRule ^latvia/rankings latvia/lv-rankings.php [NC]
RewriteRule ^latvia latvia/index.php [NC]
去拉脱维亚也行。但如果出于某种原因去拉脱维亚/2017/锦标赛(或任何其他页面),它将给出与/拉脱维亚相同的页面
最佳答案
将l添加到规则中,例如[NC, L]
以指示这是最后一次重写,否则,由于一切都以^latvia
开头,所有规则都将通过最后一个规则。
代码:
RewriteRule ^latvia/2017/tournaments latvia/2017-lv-calendar.php [NC,L]
RewriteRule ^latvia/adults/tournaments latvia/lvt_adults.php [NC,L]
RewriteRule ^latvia/juniors/tournaments latvia/lvt_juniors.php [NC,L]
RewriteRule ^latvia/federation latvia/lv-federation.php [NC,L]
RewriteRule ^latvia/juniors/rankings latvia/lvj-rankings.php [NC,L]
RewriteRule ^latvia/adults/rankings latvia/lva-rankings.php [NC,L]
RewriteRule ^latvia/rankings latvia/lv-rankings.php [NC,L]
RewriteRule ^latvia latvia/index.php [NC,L]
您始终可以使用诸如http://htaccess.mwl.be/之类的页面测试.htaccess
关于php - SEO友好的URL不起作用,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/48252761/