Dynadot .com transfer sale, only $10.12 with coupon code DYNA12, available while supplies last, ends October 31, 2026.

Help with .htaccess 301 redirect

Namecheap AuctionsNamecheap Auctions
Namecheap AuctionsNamecheap Auctions
SpaceshipSpaceship
Watch

John Doe

Established Member
Impact
36
Hi guys,

I need a little help from programming gurus here. My CMS produces URL-s like

mydomain.com/?lang=1
mydomain.com/index.php?lang=1
myaliasdomain.com/?lang=1
myaliasdomain.com/index.php?lang=1

I need to forward all of them to homepage mydomain.com/
My .htaccess includes following code

RewriteCond %{THE_REQUEST} lang=1
RewriteRule . http: // www. mydomain. com? [R=301,L]

it works perfectly for

mydomain.com/index.php?lang=1
myaliasdomain.com/index.php?lang=1

but does not redirect URL without index.php in it. What code should I use to redirect

mydomain.com/?lang=1 and myaliasdomain.com/?lang=1 as well?

Thanks a lot!
 
0
•••
The views expressed on this page by users and staff are their own, not those of NamePros.
GoDaddyGoDaddy
Bumpy, anyone?
 
0
•••
Any help appreciated!
 
0
•••
try this:

Code:
RewriteEngine On
RewriteBase /
RewriteCond %{QUERY_STRING} .
RewriteRule ^index.php /index.php [L]
 
0
•••
Thanks Shockie,
Doesn`t this code redirect all URLs that include index.php to /index.php?
 
0
•••
i think it's supposed to check if anything comes after the "?" and if something does comes after it (i.e., lang=1) then it will take out the lang=1 or whatever else and redirect to index.php.

..... i think... try it out first, lol. :guilty:
 
0
•••
shockie said:
i think it's supposed to check if anything comes after the "?" and if something does comes after it (i.e., lang=1) then it will take out the lang=1 or whatever else and redirect to index.php.

..... i think... try it out first, lol. :guilty:
Is it possible to define lang=1 somewhere in this commandline? I`m sure otherwise all my pages and all languages will be redirected to index.php (they have lang=2, id=100 etc after "?")...
 
0
•••
mmm... if you want it to only apply to index.php and lang=1, could you just append the index.php so that you redirect mydomain.com/ to mydomain.com/index.php with this?

Code:
DirectoryIndex index.php
 
0
•••
I have actually working redirection for all URLs I need except mydomain.com/?lang=1 and mydomain.com/?lang=2

mydomain.com/index.php?lang=1, mydomain.com/index.php?id=1 etc are redirected properly
 
0
•••
AIVikingsAIVikings

We're social

Escrow.com
Spaceship
Escrowly
CryptoExchange.com
Domain Recover

NamePros updates

More data. Your data. See what is new
Major update
We have made a number of features available to provide sellers more data for their domains and inquiries, and greater access to the data...
AIVikings
Catchy
  • The sidebar remains visible by scrolling at a speed relative to the page’s height.
Back