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
  • 69,448
  • 7
  • 95
  • 188
Radek
  • 640
  • 6
  • 14

4 Answers4

0

Please try this :

RewriteEngine On
RewriteCond %{REQUEST_URI} ^/([a-z].*)
RewriteRule .* http://kap.com/ [R,L]
metalfight - user868766
  • 2,692
  • 1
  • 14
  • 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
  • 69,448
  • 7
  • 95
  • 188
0
RedirectMatch 301 ^/ http://www.mydomain.com/

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

YoyoS
  • 590
  • 1
  • 6
  • 18
0

I find that solution OK

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