Solved

Redirect 301 with http://%{SERVER_NAME}

Posted on 2010-08-30
3
359 Views
Last Modified: 2013-12-13
Hello,

I need to redirect one URL to another.  This is an easy task using:

Redirect 301  /sub1/sub2/ http://www.domain.com/sub45/sub46/

BUT i need to use the dynamic http://%{SERVER_NAME} and it is not working like this:


Redirect 301  /sub1/sub2/  http://%{SERVER_NAME}/sub45/sub46/

Thanks.


0
Comment
Question by:b1xx1b
  • 2
3 Comments
 

Author Comment

by:b1xx1b
ID: 33562908
HI

I actually came up with a solution to my problem but am not clear why this works.
Perhaps an expert can explain why it works?

RewriteRule ^/?sub1/sub2/$ /sub46/sub47 [R=301,NC,L]

I stumbled across this solution somewhere online - putting the ? in the old url path seemed to do the trick.
Why?
0
 
LVL 43

Accepted Solution

by:
ravenpl earned 500 total points
ID: 33564761
So You want the '?' explained?
If You put that RewriteRule in http.conf or included file. the leading / in match-string is required, if You put it into .htaccess file, the leading / in match-string is disallowed. The '?' makes it optional - it says it can be there, but it's fine if it's not. So this '?' makes the rule universal.

Of course simple Redirect hasn't worked, as the %{SERVER_NAME} is disallowed there.
0
 

Author Closing Comment

by:b1xx1b
ID: 33567873
great answer
0

Featured Post

What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

Join & Write a Comment

Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
Since pre-biblical times, humans have sought ways to keep secrets, and share the secrets selectively.  This article explores the ways PHP can be used to hide and encrypt information.
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.

708 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now