LoicTheAztec
LoicTheAztec

Reputation: 253869

How to redirect Urls with variables to the main domain using htaccess

Using .htaccess, I have tried some things to redirect Urls with variables to main the domain www.my_domain.tld, but I didn't find the right way.

I have 2 kinds of Urls that I want to redirect to my main domain:

What I am doing wrong?

Upvotes: -1

Views: 162

Answers (1)

Amit Verma
Amit Verma

Reputation: 41219

You can use the following rule in /.htaccess :

RewriteEngine on


RewriteCond %{THE_REQUEST} /blog/\?p=([0-9]+) [OR]
RewriteCond %{THE_REQUEST} /blog/feed/\?p=([0-9]+) [NC]
RewriteRule ^ http://domain.tld? [L,R,NC]

Empty question mark at the end of the destination url is important as it discards the old query strings.

Upvotes: 4

Related Questions