.htaccess 使用LightSpeed对.htacces中的mod_重写进行故障排除
我有几个网页位于以下位置:.htaccess 使用LightSpeed对.htacces中的mod_重写进行故障排除,.htaccess,mod-rewrite,litespeed,.htaccess,Mod Rewrite,Litespeed,我有几个网页位于以下位置: Home Page / Index : www.codeliger.com/index.php?page=home Education : www.codeliger.com/index.php?page=home&filter=1 Skills: www.codeliger.com/index.php?page=home&filter=2 Projects: www.codeliger.com/index.php?page=home&filt
Home Page / Index : www.codeliger.com/index.php?page=home
Education : www.codeliger.com/index.php?page=home&filter=1
Skills: www.codeliger.com/index.php?page=home&filter=2
Projects: www.codeliger.com/index.php?page=home&filter=3
Work Experience: www.codeliger.com/index.php?page=home&filter=4
Contact : www.codeliger.com/index.php?page=contact
我正在尝试将它们重写为更漂亮的URL:
codeliger.com/home
codeliger.com/education
codeliger.com/skills
codeliger.com/projects
codeliger.com/experience
codeliger.com/contact
我已经确认我的htaccess文件和mod rewrite对谷歌有效,但我无法使用多个在线教程中指定的语法
RewriteEngine on
RewriteRule /home /index.php?page=home
RewriteRule /([a-Z]+) /index.php?page=$1
RewriteRule /education /index.php?page=home&filter=1
RewriteRule /skills /index.php?page=home&filter=2
RewriteRule /projects /index.php?page=home&filter=3
RewriteRule /experience /index.php?page=home&filter=4
如何修改语法以将这些页面重写为更漂亮的URL?您可能要做的第一件事是修改正则表达式。您不能拥有像
[a-Z]
这样的范围,您只需执行[a-Z]
并使用[NC]
(无大小写)标志即可。此外,您希望将此规则放在最后,因为它将匹配/projects
的请求,这将使它变得更加简单,因此,再往下一步的规则将永远不会被应用。然后,你想摆脱所有的领先斜杠。最后,您需要为正则表达式设置一个边界,否则它将匹配index.php
,并导致另一个错误
因此:
RewriteEngine on
RewriteRule ^home /index.php?page=home
RewriteRule ^education /index.php?page=home&filter=1
RewriteRule ^skills /index.php?page=home&filter=2
RewriteRule ^projects /index.php?page=home&filter=3
RewriteRule ^experience /index.php?page=home&filter=4
RewriteRule ^([a-z]+)$ /index.php?page=$1 [NC]