user3132858
user3132858

Reputation: 667

How to properly redirect an URL with .htaccess

I am trying to redirect this url www.site.com/page.php?sortchar=a to www.site.com/page/a/ with the below rule, however I cannot find the right structure. The sortchar variable can be any letter of the alphabet so I am trying to do all letters with one rule:

RewriteCond %{THE_REQUEST} \ /+page\.php\?sortchar=$1
RewriteRule ^ /page/([^/]*)/? [L,R]

Anyone can help?

Upvotes: 1

Views: 37

Answers (1)

anubhava
anubhava

Reputation: 785541

You cannot use $1 in RewriteCond without first capturing it.

You can use:

RewriteCond %{THE_REQUEST} \s/+page\.php\?sortchar=([^&\s]+) [NC]
RewriteRule ^ /page/%1? [L,R]

Upvotes: 1

Related Questions