Forum Moderators: phranque

Message Too Old, No Replies

htaccess rewrite is redirecting to the full server path. bad!

         

httpwebwitch

3:51 pm on Dec 29, 2011 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I want to redirect all requests for folder1 to folder2.

for example, a request for
http://example.com/folder1/page.html

should get a 301 to

http://example.com/folder2/page.html

my rule:

RewriteRule ^folder1/(.*)$ /folder2/$1 [R=301,L]



but instead, it's sending my browser to the full server path:

http://example.com/var/www/public_html/folder2/page.html



what am I doing wrong?

g1smd

3:57 pm on Dec 29, 2011 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



You probably have another rule ahead of the redirect which performs an internal rewrite.

The redirect then exposes the previously rewritten internal path back out on to the web as a new URL.

You should list all redirects before you list any rewrites.

Redirects and rewrites should all use RewriteRule syntax with the appropriate flags. Don't use the Redirect or RedirectMatch directives. Use RewriteRule for everything.

httpwebwitch

3:06 pm on Dec 31, 2011 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



this redirect rule is the first thing in the .htaccess ; there's nothing else above it that would cause trouble

g1smd

6:28 pm on Dec 31, 2011 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



How about in a higher level folder or in the main site config?

httpwebwitch

9:32 pm on Dec 31, 2011 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



it's the .htaccess in the document root

I've tried a few variations & experiments; still getting a redirect to the "real" path instead of the relative one. I'm perplexed.

lucy24

6:47 am on Jan 1, 2012 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Are you on shared hosting or is it your own server? If it's your own, you shouldn't need htaccess at all except for highly local things like selectively turning auto-indexing off or on. If it's shared, then there are many, many layers above your userspace before you get to the config file.

What does the config file have to say about mod_rewrite? Any unusual settings for RewriteBase?