Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

I currently have a perm_redirects.conf file that gets included into my apache config stack where I have lines in the format

RedirectPermanent /old/url/path /new/url/path

It looks like I'm required to use an absolute URL for the new path, e.g.: http://example.com/new/url/path. In the logs I'm getting "incomplete redirect target /new/url/path was corrected to http://example.com/new/url/path." (paraphrased).

In the 2.2 docs for RewriteRule, at the bottom they show the following as being a valid redirect, with only the url-paths instead of an abs URL for the right hand side of the redirect:

RewriteRule ^/old/url/path(.*) /new/url/path$1 [R]

But I can't seem to get that format to work to replicate the functionality of the RedirectPermanent version. Is this possible?

share|improve this question
    
RewriteRule ^old/url/path(.*)$ new/url/path$1 [L] –  Prix Aug 9 '10 at 22:37

1 Answer 1

WFM:

RewriteEngine On
RewriteOptions Inherit 
RewriteRule ^/old/url/path(.*) /new/url/path$1 [R]

Result:

wget http://localhost/old/url/path/foo
--2010-08-09 15:41:20--  http://localhost/old/url/path/foo
Resolving localhost... 127.0.0.1
Connecting to localhost|127.0.0.1|:80... connected.
HTTP request sent, awaiting response... 302 Found
Location: http://localhost/new/url/path/foo [following]
--2010-08-09 15:41:20--  http://localhost/new/url/path/foo

Note (1) you probably want [R=permanent]. The default is a temp redirect. (2) You do not want just the [L] as that will result in an internal redirect invisible to the end user (not caused by the L, the default action "" is an internal redirect). RedirectPermanent generates a 3xx response to the end user. You could add the L, i.e., [R=permanent,L] to stop mod_rewrite from processing any more rules.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.