+ Reply to Thread
Results 1 to 4 of 4

Thread: .htaccess redirect

  1. #1
    driveflexfuel is offline x10 Sophmore driveflexfuel is an unknown quantity at this point
    Join Date
    Jul 2008
    Posts
    159

    .htaccess redirect

    This is an example of our old dynaimc product URL:
    http://www.site.com/Merchant2/merchant.mvc?Screen=PROD&Product_Code=cm028-ak47-airsoft&Category_Code=&Store_Code=R

    we are now using static pages

    We need htaccess to reconize the product code which is cm028-ak47-airsoft then smiply redirct with 301 to the new static page which is http://www.site.com/cm028-ak47-airsoft.html

    any help is greatly appreciated


    Is this something that can be edited to work

    # Enable mod_rewrite, start rewrite engine
    Options +FollowSymLinks
    RewriteEngine on
    #
    # Internally rewrite search engine friendly static URL to dynamic filepath and query
    RewriteRule ^product/([^/]+)/([^/]+)/([^/]+)/([^/]+)/([^/]+)/?$ /index.php?product=$1&color=$2&size=$3&texture=$4&m aker=$5 [L]
    #
    # Externally redirect client requests for old dynamic URLs to equivalent new static URLs
    RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /index\.php\?product=([^&]+)&color=([^&]+)&size=([^&]+)&texture=([^&]+)&maker=([^\ ]+)\ HTTP/
    RewriteRule ^index\.php$ http://example.com/product/%1/%2/%3/%4/%5? [R=301,L]
    Last edited by driveflexfuel; 02-03-2010 at 11:20 AM.

  2. #2
    marshian's Avatar
    marshian is offline x10 Elder marshian is an unknown quantity at this point
    Join Date
    Jan 2008
    Location
    Belgium
    Posts
    526

    Re: .htaccess redirect

    I haven't tested it, but I think something like this should work:
    Code:
    RewriteEngine on
    RewriteRule ^Merchant2/merchant\.mvc\?(.*&)?Product_Code=([^&]+)(&.*)? /$2.html [R=301,L]
    Real programmers don't document their code - if it was hard to write, it should be hard to understand.

  3. #3
    descalzo's Avatar
    descalzo is offline Grim Squeaker descalzo has a brilliant futuredescalzo has a brilliant futuredescalzo has a brilliant future
    Join Date
    Jul 2009
    Location
    Ankh-Morpork
    Posts
    7,636

    Re: .htaccess redirect

    Code:
    RewriteCond  %{REQUEST_URI}  ^/Merchant2/merchant.mvc
    RewriteCond %{QUERY_STRING} Product_Code=([^&]*)
    RewriteRule  .*  /%1.html? [R=301,L]

    Note: This does not test that you have a product file for the Product Code.
    Nothing is always absolutely so.

  4. #4
    misson is offline x10 Spammer misson is a jewel in the rough
    Join Date
    Mar 2008
    Location
    Libertatia
    Posts
    2,506

    Re: .htaccess redirect

    RewriteRules don't match against the query string. You'll need to use a RewriteCond:

    Code:
    RewriteCond %{QUERY_STRING} (^|&)Product_Code=([^&]*)
    RewriteRule ^/?Merchant2/merchant\.mvc /%1.html [R=301]
    Depending on how exactly the site is arranged, you might need to remove the leading slash from the replacement string.

    I'm assuming when you say "We need htaccess to reconize the product code which is cm028-ak47-airsoft", the "cm028-ak47-airsoft" is merely an example and you want the rewrite to work with any product code (you might want to work on your writing clarity).

    When you're posting code or configuration, use one of the [CODE], [PHP] or [HTML] tags to separate it from the rest of the post, as marshian and I have done. It makes it much easier to read.
    Last edited by misson; 02-03-2010 at 02:42 PM.
    Be sure to read all pages linked in this post; they have further information that should prove useful. When asking for help, make sure you follow Eric Raymond's and Jon Skeet's guidelines for prompt, accurate responses. Please answer any questions I ask; they're not rhetorical (probably). Any posted code is intended as illustrative example, rather than a solution to your problem to be copied without alteration. Study it to learn how to write your own solution.
    Misson, not Mission.

+ Reply to Thread

Similar Threads

  1. Use .htaccess to redirect everyone except you
    By ah-blabla in forum Tutorials
    Replies: 5
    Last Post: 10-14-2009, 05:02 AM
  2. .htaccess redirect with regular expressions
    By Scoochi2 in forum Programming Help
    Replies: 0
    Last Post: 08-25-2008, 07:07 AM
  3. .htaccess 301 redirect help
    By skeets in forum Programming Help
    Replies: 6
    Last Post: 05-04-2008, 08:00 PM
  4. default .htaccess
    By Fedlerner in forum Computers & Technology
    Replies: 9
    Last Post: 09-05-2007, 09:10 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
x10hosting free hosting for the masses
dedicated servers