Solved

Redirect 301 with http://%{SERVER_NAME}

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

Windows Server 2016: All you need to know

Learn about Hyper-V features that increase functionality and usability of Microsoft Windows Server 2016. Also, throughout this eBook, you’ll find some basic PowerShell examples that will help you leverage the scripts in your environments!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Apache error.log 19 43
str_replace not working in php script 4 31
preventing spam with mailto 22 33
write screen output to text file 21 47
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…
3 proven steps to speed up Magento powered sites. The article focus is on optimizing time to first byte (TTFB), full page caching and configuring server for optimal performance.
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…
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 …

810 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