1

I have a couple web pages located at these locations:

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

I am trying to rewrite them to prettier urls:

codeliger.com/home
codeliger.com/education
codeliger.com/skills
codeliger.com/projects
codeliger.com/experience
codeliger.com/contact

I have confirmed that my htaccess file works and mod-rewrite works to google, but I cannot get my syntax working that was specified in multiple tutorials online.

  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

How can I fix my syntax to rewrite these pages to prettier urls?

4

1 回答 1

1

您可能应该做的第一件事是修复您的正则表达式。你不能有一个范围[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]
于 2013-12-18T01:25:36.803 回答