Praful
Praful

Reputation: 11

htaccess rule for internal redirection is not working?

http://www.example.com/class/part-time/ is the actual url.

I want to write htaccess rule for internal redirection to url:

http://www.example.com/index.php?type=class&slug=part-time

and I am using following rule-

RewriteRule ^class/([\w-]*)/$ index.php?slug=$1&type=class

But it is not working.

Upvotes: 0

Views: 37

Answers (1)

machineaddict
machineaddict

Reputation: 3236

One method would be:

RewriteRule ^class/([\w-]+)/$ index.php?slug=$1&type=class [L,QSA]

And another would be:

RewriteRule ^([\w-]+)/([\w-]+)/$ index.php?slug=$2&type=$1 [L,QSA]

Notes:
* I didn't tested it, but you should get the idea...
* The first method's url must start with the word class, the second one's is for dinamic urls
* Don't forget the [L] flag on your rules, as not using it might get unexpected results
* Don't forget the [QSA] flag on your rules if you are appending other GET values
* $1 catches everything from ([\w-]+) set, $2 from the second set
* I used ([\w-]+) instead of ([\w-]*) as that part of url is mandatory

Upvotes: 0

Related Questions