Forum Moderators: phranque
I tried searching, and found a few threads, but this one seemed to be what I needed:
[webmasterworld.com...]
Turns out, it's not working.
All I need to do is to redirect my entire site:
www.example.com
to
www.example.com/folder
What's the best way to do this with .htaccess? It seems simple enough, but for some reason it's not working :)
Thanks everyone, and happy holidays!
I really need this code too - just spend a day pasting something that doesn't do the trick. Need to rewrite:
example.com & www.example.com
->
example.com/subfolder & www.example.com/subfolder
MAIN PROBLEM is that current rewrite doesn't initially show /subfolder in url.
Here is my current htaccess:
RewriteEngine on
RewriteCond %{HTTP_HOST} ^(www.)?example.com$
RewriteCond %{REQUEST_URI} !^/subfolder/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /blog/$1
RewriteCond %{HTTP_HOST} ^(www.)?example.com$
RewriteRule ^(/)?$ subfolder/index.php [L]
This would really make my holliday!
Thanks in advance.
RewriteEngine on
RewriteCond %{HTTP_HOST} ^(www\.)?example\.com$ [NC]
RewriteRule ^$ [%{HTTP_HOST}...] [R,L]
This redirects requests without any path information (that's http://www.example.com/) into the index.php located in the subfolder directory.
If you have some mod_rewrite directives in the htaccess file, then make sure this is placed on top of the rules, so in the case of aschepelern's post, it should look like this:
RewriteEngine on
#
# Redirect into subfolder when no path information in request
RewriteCond %{HTTP_HOST} ^(www\.)?example\.com$ [NC]
RewriteRule ^$ [%{HTTP_HOST}...] [R,L]
#
# Rewrite into blog when request is not for anything in subfolder
# and when the request is not for an existing file or directory.
# Actually the first condition (the subfolder one) is not really needed, because
# subfolder exists (based on your example), so the second two conditions
# would take care of it anyway.
RewriteCond %{HTTP_HOST} ^(www\.)?example\.com$ [NC]
RewriteCond %{REQUEST_URI} !^/subfolder/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /blog/$1 [L]
Change it to [R=301,L] to make it into a 301 redirect.
One point. In the questions above, one person asked for a rewrite and the other asked for a redirect.
The redirect makes the browser ask for a new and different URL when a particular URL (or set of URLs) is/are asked for.
A rewrite ensures the same old external URL still works for accessing some content after that content was physically placed in a different place inside the server.
You need to be very clear which one of those two things you actually want.
If you're having to move the stuff around on the server, you'd normally employ a rewrite so that users use the same old URLs to access that content. They would never know you had changed the internal way the site operated.
Maybe you could go into a bit more detail why you think you need to redirect to new URLs? (I'm not saying you're wrong, but rather that what you think you need, might be better done some other way).
www.example.com/blue-widget-1.html
www.example.com/blue-widget-2.html
www.example.com/blue-widget-3.html
I want all of the color widgets, so I want to change it to:
www.example.com/blue/widget-1.html
www.example.com/red/widget-1.html
www.example.com/black/widget-1.html
the index page of the site would ask users what color widgets they want
But before I add the other colors, I need to redirect everything on the site now into one folder, let google get the changes, and then add the other colors.
What do you suggest? Does my idea make sense?
Thanks