views:

64

answers:

1

This is my .htaccess file but it is not working. Not any URL is redirected. Help me.

RewriteEngine on
RewriteRule ^home index.php
RewriteRule ^contactus index.php?file=c-contactus
RewriteRule ^course_registration index.php?file=c-course_registration
RewriteRule ^ncplhpage index.php?file=c-ncplhpage
RewriteRule ^scplhpage index.php?file=c-scplhpage
RewriteRule ^corporatetra index.php?file=c-corporatetra
A: 

You may need to set a RewriteBase.

However, I suspect the problem is the lack of a / before index.php in all cases, i.e.

RewriteEngine on
RewriteRule ^home /index.php

As a side point, have you considered combining your directives into a single directive like:

RewriteRule ^(home|contactus|course_registration|ncplhpage|scplhpage|corporatetra)$ /index.php?file=c-$1

? You could take this a step further and hand down the checking of the name into your index.php file itself, i.e.

RewriteRule ^([_a-z]+)$ /index.php?file=c-$1

Bear in mind that your index.php should be checking that the $_GET['file'] that is requested is valid. Just because you have public URLs like /contactus doesn't mean that someone still can't type in /index.php?file=c-contactus directly (try it!). That means they could therefore type in /index.php?file=c-../../../../etc/passwd for instance. So do ensure that your index.php does some sanity-checking as well. That will be good both for security but also mean that you can avoid hard-coding your URLs into your .htaccess file.

fooquency