Results 1 to 6 of 6

Thread: htaccess help static to dynamic redirect

  1. #1
    Join Date
    Nov 2009
    Posts
    107
    Thanks
    7
    Thanked 2 Times in 2 Posts

    Default htaccess help static to dynamic redirect

    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.

  2. #2
    Join Date
    Apr 2008
    Location
    So.Cal
    Posts
    3,643
    Thanks
    63
    Thanked 517 Times in 503 Posts
    Blog Entries
    5

    Default

    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.

  3. #3
    Join Date
    Nov 2009
    Posts
    107
    Thanks
    7
    Thanked 2 Times in 2 Posts

    Default

    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.
    Last edited by itivae; 01-07-2012 at 07:59 PM.

  4. #4
    Join Date
    Apr 2008
    Location
    So.Cal
    Posts
    3,643
    Thanks
    63
    Thanked 517 Times in 503 Posts
    Blog Entries
    5

    Default

    Quote Originally Posted by itivae View Post
    how to redirect say

    http://www.example.com/memberpages/L..._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.
    Quote Originally Posted by itivae View Post
    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).
    Quote Originally Posted by itivae View Post
    Would my redirect look like this?

    RewriteRule ^memberpages/Lakeside_Haven_BB.html http://bartonchamber.com.tempwebpage.com/?page_id=183
    that 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

    Quote Originally Posted by itivae View Post
    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.

    Quote Originally Posted by itivae View Post
    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.
    Last edited by traq; 01-08-2012 at 02:10 AM.

  5. The Following User Says Thank You to traq For This Useful Post:

    itivae (01-03-2012)

  6. #5
    Join Date
    Nov 2009
    Posts
    107
    Thanks
    7
    Thanked 2 Times in 2 Posts

    Default

    Thanks for the information. I will try it out and see how it goes. Thanks again.

  7. #6
    Join Date
    Apr 2008
    Location
    So.Cal
    Posts
    3,643
    Thanks
    63
    Thanked 517 Times in 503 Posts
    Blog Entries
    5

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •