1

i want to create a clean url, as in, let say, i have a site www.mywebsite.com, i want, if anybody tries http://www.mywebsite.com/something, he should get redirected to www.mywebsite.com,

so any thing that is typed ahead of mywebsite.com/ they should get redirected to www.mywebsite.com

how can i do this in .htaccess, kindly help.

Suhail
  • 2,847
  • 2
  • 19
  • 16
  • Are you wanting only if the "something" doesn't exist to redirect, or are you planning to have no sub-content? – Simeon Pilgrim Jun 21 '10 at 15:26
  • no no, i want like, if you try to access http://www.mywebsite.com/anything, it should go to http://www.mywebsite.com there should be nothing ahead of http://www.mywebsite.com/ the url should be clean, in the address bar it should only show http://www.mywebsite.com – Suhail Jun 21 '10 at 15:30

2 Answers2

1
RewriteEngine ON
RewriteRule ^/.+ / [L,R]

That will redirect everything to / as a permanent redirect. Look at http://httpd.apache.org/docs/2.0/mod/mod_rewrite.html for more information on the flags you can add for transparency etc etc.

If you want this in .htaccess make sure you have the correct override directives in your <VirtualHost > config.

Matt S
  • 1,767
  • 8
  • 9
0

If you want to only redirect if there files and directories don't exists already, then this will work:

RewriteEngine ON
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^/.+ / [R,L]

If you never want to have sub-content accessible then remove the condition rules

RewriteEngine ON
RewriteRule ^/.+ / [R,L]
Simeon Pilgrim
  • 22,906
  • 3
  • 32
  • 45