Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Redirect 301 with http://%{SERVER_NAME}

Posted on 2010-08-30
3
Medium Priority
?
371 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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 2000 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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Password hashing is better than message digests or encryption, and you should be using it instead of message digests or encryption.  Find out why and how in this article, which supplements the original article on PHP Client Registration, Login, Logo‚Ķ
This article discusses how to implement server side field validation and display customized error messages to the client.
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn how to count occurrences of each item in an array.
Suggested Courses

604 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