Buying .Htaccess expert needed for a quick (hopefully) fix

Discussion in 'Programming' started by Deadsquirrel, Jan 13, 2014.

  1. #1
    Hi All, I am in need of an .htaccess expert to fix a small bug on a redirect we have.

    Basically, a simple url to url redirect is affected by another line in the htaccess file.

    I was going to post this up as a help topic but we find that we need htaccess work quite often so it would be good to find a real expert in this field for future work. Please only reply if you are VERY confident with .htaccess.

    Regards,
    DS
     
    Deadsquirrel, Jan 13, 2014 IP
  2. cLogik

    cLogik Active Member

    Messages:
    159
    Likes Received:
    28
    Best Answers:
    0
    Trophy Points:
    90
    As Seller:
    100% - 0
    As Buyer:
    100% - 1
    #2
    Do you mind posting the bug? :)
     
    cLogik, Jan 13, 2014 IP
  3. Deadsquirrel

    Deadsquirrel Well-Known Member

    Messages:
    194
    Likes Received:
    27
    Best Answers:
    0
    Trophy Points:
    120
    As Seller:
    100% - 0
    As Buyer:
    100% - 0
    #3
    Ok, here is the problem:
    We have a example.co.uk site and a example.com site. Both are Drupal based.

    The htaccess file is on the .co.uk

    We want to redirect http://www.example.co.uk/this-url.htm to http://www.example.com/this-url (NOTE: Not the whole site, just this url and note the .htm on the source and no .htm on the destination)

    So we have in the htaccess:
    Redirect 301 /this-url.htm http://www.example.com/this-url

    This should work fine, but its producing the following url:
    http://www.example.com/this-url?q=this-url.htm

    The reason is because of the last line in this htaccess block:
    # Rewrite URLs of the form 'x' to the form 'index.php?q=x'.
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_URI} !=/favicon.ico
    RewriteRule ^(.*)$ index.php?q=$1 [L,QSA]

    We cannot comment that line out as it is needed by Drupal.
    We are not able to provide FTP access (hence needing someone good at htaccess) but I am more than happy to send you the actual htaccess file for you to fix and us to upload.

    Anyone able to help?
     
    Last edited: Jan 13, 2014
    Deadsquirrel, Jan 13, 2014 IP
  4. Nigel Lew

    Nigel Lew Notable Member

    Messages:
    4,642
    Likes Received:
    406
    Best Answers:
    21
    Trophy Points:
    295
    As Seller:
    100% - 0
    As Buyer:
    100% - 0
    #4
    Can you paste the rewrite base part. I think the answer could be here https://drupal.org/node/38960
    You may simply need to process that rule first but I typically have to fiddle with things a bit so its a bit of trial and error.
    #custom redirects
    RewriteRule ^old/URL/path$ http://example.com/new/path [R=301,L]
    #end custom redirects

    N.
     
    Nigel Lew, Jan 13, 2014 IP
  5. SecondV

    SecondV Active Member

    Messages:
    76
    Likes Received:
    7
    Best Answers:
    0
    Trophy Points:
    70
    As Seller:
    100% - 1
    As Buyer:
    100% - 0
    #5
    Assuming this still isn't working for you, what Nigel mentioned is correct. Your current .htaccess is appending the query string because it does not stop parsing after your redirect. So you could do something like:

    
    RewriteEngine On
    RewriteRule ^this\-url.htm$  http://www.example.com/this-url [R=301,L]
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_URI} !=/favicon.ico
    RewriteRule ^(.*)$ index.php?q=$1 [L,QSA]
    
    Code (markup):
    Which should work.
     
    SecondV, Jan 14, 2014 IP