views:

32

answers:

2
+1  Q: 

.htaccess redirect

hi,

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.

+1  A: 
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
hey matt, i tried that, but its not working.
Suhail
i have the following directives set in my virtual host:<Directory /> Options FollowSymLinks AllowOverride None </Directory>is this correct ?
Suhail
Change `AllowOverride` to `All`, give that a try
Matt S
A: 

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
You need the `R` flag; otherwise, it's transparent to the user.
Álvaro G. Vicario
no, that doesn't work
Suhail
Agreed Alvaro, thanks.
Simeon Pilgrim