SitePoint Sponsor

User Tag List

Results 1 to 5 of 5
  1. #1
    SitePoint Member
    Join Date
    May 2012
    Posts
    3
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Need Help Redirecting Dynamic URL to Already Exisitng URL

    I have been reading many forums and tutorials on mod_rewrite, but the truth is, I am very inexperienced in this area and unfortunately have the responsibility of successfully executing these redirects.

    I am trying to 301 redirect 3 dynamic URLs to the existing homepage http://www.mydomain.com

    http://www.mydomain.com/index.php?ma...roducts_id=603
    http://www.mydomain.com/wine-cabinet...cPath=8_17_161
    http://www.mydomain.com/dometic-wine...cPath=8_12_102


    I'm not sure if I should use a {Query_String} rewrite or something like this:

    RewriteRule ^([a-z/]+)\.html$ $1.php [R=301,L] I'm also not sure if I should write separate rules for each domain or use one rule for all three. Any insight would really be appreciated.


    mod_rewrite is enabled on my .htaccess File.

  2. #2
    Certified Ethical Hacker silver trophybronze trophy dklynn's Avatar
    Join Date
    Feb 2002
    Location
    Auckland
    Posts
    14,607
    Mentioned
    19 Post(s)
    Tagged
    2 Thread(s)
    EC,

    If you want to be more experienced in this (mod_rewrite) area, I offer the tutorial article linked in my signature as it was developed and used by many SitePoint members over the last 5-6 years.

    I do not like to provide code here because "script kiddies" do not learn and that's my intent for being here ("share the knowledge"). However, your request is so simple, I'll go ahead and help with the code provided you read enough of the tutorial that you understand what the code is doing.

    Code:
    RewriteEngine on
    
    RewriteCond %{QUERY_STRING} ^main_page=product_info&cPath=8_251_81&products_id=603$
    RewriteRule ^index\.php$ http://www.mydomain.com/ [R=301,L]
    
    RewriteCond %{QUERY_STRING} ^cPath=8_17_161$
    RewriteRule ^wine-cabinets-perlick-stand-alone-frw$ http://www.mydomain.com/ [R=301,L]
    
    RewriteCond %{QUERY_STRING} ^cPath=8_12_102$
    RewriteRule ^dometic-wine-cabinets-dom-cs52vs$ http://www.mydomain.com/ [R=301,L]
    You were quite correct in saying that you should use an Apache variable (other than {REQUEST_URI}) to access the query string and, because RewriteRules can only access {REQUEST_URI}, you must use RewriteCond's to test the query string.

    I could not combine these three RewriteRule sets because the target scripts (pages?) were different.

    Regards,

    DK
    David K. Lynn - Data Koncepts is a long-time WebHostingBuzz (US/UK)
    Client and (unpaid) WHB Ambassador
    mod_rewrite Tutorial Article (setup, config, test & write
    mod_rewrite regex w/sample code) and Code Generator

  3. #3
    SitePoint Member
    Join Date
    May 2012
    Posts
    3
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    DK-

    Your help is greatly appreciated and I looking forward to reading your tutorial; it's important to me to gain an understanding of mod_rewrite for future instances.

    Thank you,

    Erica

  4. #4
    SitePoint Member
    Join Date
    May 2012
    Posts
    3
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    These I'm sure are rather trivial questions, but is there a specific place on the .htaccess file to put the script? Also, do you use the script in addition to or instead of the regular 301 redirects? I have tried both, but am unable to get it to work.

  5. #5
    Certified Ethical Hacker silver trophybronze trophy dklynn's Avatar
    Join Date
    Feb 2002
    Location
    Auckland
    Posts
    14,607
    Mentioned
    19 Post(s)
    Tagged
    2 Thread(s)
    EC,

    I don't believe that it matters but Apache will process core directives before mod_rewrite every time. Therefore, as a matter of process (so my thinking remains inline with the server's processing, I put all core directives (Options, <File>, DirectoryIndex, ErrorDocument and, yes, Redirect) at the top then add my mod_rewrite after that.

    Regards,

    DK
    David K. Lynn - Data Koncepts is a long-time WebHostingBuzz (US/UK)
    Client and (unpaid) WHB Ambassador
    mod_rewrite Tutorial Article (setup, config, test & write
    mod_rewrite regex w/sample code) and Code Generator


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
  •