View Full Version : htaccess help static to dynamic redirect
itivae
01-02-2012, 10:35 PM
Hello,
I am hoping that someone can explain the htaccess 301 redirect for me. I want to redirect a static .html to a dynamic ?id=1 format. However, I am unclear on the actual steps to create this.
I have done some reading and will try to explain what I understand to the best of my ability. Any help with this would be appreciated.
RewriteEngine on //allows server to process the redirect
RewriteCond %{QUERY_STRING} ^id=13$
//if page=id13 then redirect (however I wish to redirect a static address to a dynamic one is there another protocol to do this?)
RewriteRule ^/page.php$ http://www.example.com/newname.htm? [L,R=301]
//page is the variable for the root (ie index.php? page.php? ect. and is replaced with whichever dynamic root is used on the cms). I am unclear of whether the url following the "page.phpvariable" is the old address or the new one.
Can someone please help me to understand this a bit better or show me some code that would work to redirect several hundred static html pages to a dynamically generated cms?
Thanks a lot in advance.
I think you've confused most of what you're talking about, there. for example:
* a "static address" is always the same - there's no point in redirecting it dynamically, since the input never changes (and therefore, the output will always be the same as well)... unless you want it dynamically written based on some other criteria (IP, referrer, time of day, etc.).
* what do you mean by "page is the variable for the root"? the "root" is the directory that shows up when you enter the domain without a path (i.e., http://example.com/). There are no "variables" in .htaccess: matched patterns in conditions or rules can be "referenced" using %1, %2, etc. - is that what you're talking about?
* in your example:
RewriteRule ^/page.php$ http://www.example.com/newname.htm? [L,R=301]
-- "/page.php" is the address you want to redirect
-- "http://www.example.com/newname.htm?" is the address you want to redirect to
-- "R=301" makes this a permanent redirect: the new address shows up in the user's browser, which is a hint that it should (always) be used instead of the original URL.
Here's a couple questions to help clarify what you want to do:
1. what URI will the user type in the address bar? Give a concrete example, and also describe the format.
2. what does the user's URI need to be redirected to? Describe what parts of the URI correspond to each part of the redirect.
itivae
01-03-2012, 12:19 AM
Thanks for taking the time traq. I understand that a static address is always the same. What I am trying to figure out is how to redirect say
http://***********.html
to
http://***********
However this is just a temp url (ie the http://***************) will change. Will the redirects need to be done after the change to the live url? or will a redirect in the cms settings (ie http://************ = http://www.bartonchamber.com) make the current redirects remain legit?
Would my redirect look like this?
RewriteRule ^memberpages/************* http://***************
Since there is not pattern I will need to manually redirect all 200 pages correct?
If the above example is correct could you explain how it knows where the redirect is comming from (ie it says ^memberpages/***********....how does it know that it came from
http://*************)?
Sorry Im new at this aspect. I really appreciate the help.
Thanks again.
how to redirect say
http://www.example.com/memberpages/Lakeside_Haven_BB.html
to
http://example.com.tempwebpage.com/?page_id=183
However this is just a temp url ... Will the redirects need to be done after the change to the live url?
...how "temporary"? Yes, the redirects will remain, but they will still point at the temporary site.
or will a redirect in the cms settings (ie http://www.example.tempwebpage.com = http://www.example.com) make the current redirects remain legit?
what do you mean by "cms redirect"? if you are asking if you can set up something like this:
currentsite.com --> temporarysite.com --> eventualsite.com
then the short answer is yes, but I wouldn't do it. it's unnecessarily complicated and fragile (e.g., will you always have temporarysite.com? you're forcing yourself to maintain it at least as long as your maintain currentsite.com).
Would my redirect look like this?
RewriteRule ^memberpages/Lakeside_Haven_BB.html http://bartonchamber.com.tempwebpage.com/?page_id=183that will work, and probably will do what you expect. it would be better to specify the actual page you want, however, instead of just the domain and query string:
RewriteRule ^memberpages/Lakeside_Haven_BB.html ]http://example.com.tempwebpage.com/filename.extension?page_id=183
Since there is not pattern I will need to manually redirect all 200 pages correct?
if there's no pattern, then yes, every page would need its own RewriteRule.
It would be well worth your while, though, to create some kind of pattern -- for example, set up your new DB so it's possible to look up the pages by their old names -- but how and if this would work would depend on your new CMS.
If the above example is correct could you explain how it knows where the redirect is comming from (ie it says ^memberpages/Lakeside_Haven_BB.html....how does it know that it came from
http://www.example.com)?
Where the redirect is coming from -meaning, the page the user was on previously- could be determined by using %{HTTP_REFERER}. On temporarysite.com, this would correspond to the page on currentsite.com that the user tried to visit.
If you meant something else with any of these questions, let me know.
itivae
01-03-2012, 12:11 PM
Thanks for the information. I will try it out and see how it goes. Thanks again.
Powered by vBulletin® Version 4.2.2 Copyright © 2021 vBulletin Solutions, Inc. All rights reserved.