Troubleshooting mod_rewrite in a .htacces with a LightSpeed

391 views Asked by At

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?

1

There are 1 answers

0
Jon Lin On BEST ANSWER

The first thing you should probably do is fix your regex. You cannot have a range like [a-Z], you can just do [a-z] and use the [NC] (no case) flag. Also, you want this rule at the very end since it'll match requests for /projects which will make it so the rule further down will never get applied. Then, you want to get rid of all your leading slashes. Lastly, you want a boundary for your regex, otherwise it'll match index.php and cause another error.

So:

  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]