Solved

Redirect 301 with http://%{SERVER_NAME}

Posted on 2010-08-30
3
362 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

Microsoft Certification Exam 74-409

Veeam® is happy to provide the Microsoft community with a study guide prepared by MVP and MCT, Orin Thomas. This guide will take you through each of the exam objectives, helping you to prepare for and pass the examination.

Question has a verified solution.

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

Author Note: Since this E-E article was originally written, years ago, formal testing has come into common use in the world of PHP.  PHPUnit (http://en.wikipedia.org/wiki/PHPUnit) and similar technologies have enjoyed wide adoption, making it possib…
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…
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

807 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