0

I would like to redirect all pages like:

www.mydomain.com/test
www.mydomain.com/test2/test3

and so on ...

to always base

www.mydomain.com

How can i do this?

RewriteCond %{HTTP_HOST} ^www.mydomain.com 
RewriteCond %{THE_REQUEST} ^/(.*)$
RewriteRule (.*) http://%{HTTP_HOST} [L,QSA,R=301]

wont work

Olaf Dietsche
  • 72,253
  • 8
  • 102
  • 198
Radek
  • 670
  • 7
  • 16

4 Answers4

0

Please try this :

RewriteEngine On
RewriteCond %{REQUEST_URI} ^/([a-z].*)
RewriteRule .* http://kap.com/ [R,L]
metalfight - user868766
  • 2,722
  • 1
  • 16
  • 20
0

Just leave out the RewriteConds and redirect everything to /

RewriteCond %{REQUEST_URI} !^/$
RewriteRule ^ / [R,L]

When everything works as you expect, you can change R to R=301. Never test with 301 enabled, see this answer Tips for debugging .htaccess rewrite rules for details.

Community
  • 1
  • 1
Olaf Dietsche
  • 72,253
  • 8
  • 102
  • 198
0
RedirectMatch 301 ^/ http://www.mydomain.com/

It will redirect everything to your new domain. This will work if you have mod_alias

YoyoS
  • 639
  • 1
  • 7
  • 19
0

I find that solution OK

RewriteCond %{HTTP_HOST} ^www.mydomain.com
RewriteCond %{REQUEST_URI} ^/[a-zA-Z0-9\/]+$
RewriteRule ^ / [R,L]
Radek
  • 670
  • 7
  • 16