Dynadot โ€” .com Registration $8.99

Help with .htaccess 301 redirect

Spaceship Spaceship
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.
Unstoppable DomainsUnstoppable Domains
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
•••
Appraise.net
Unstoppable Domains
Domain Recover
DomainEasy โ€” Live Options
  • The sidebar remains visible by scrolling at a speed relative to the pageโ€™s height.
Back