Results 1 to 5 of 5
  1. #1
    Join Date
    May 2009
    Posts
    413
    Plugin Contributions
    0

    Default .htaccess file check please : )

    Hello,

    I just wanted to check that my .htaccess file looks ok to you guys if that's alright...

    PHP Code:
    Options +FollowSymLinks
    RewriteEngine on
    RewriteBase 
    /

    RewriteCond %{HTTP_HOST} ^mydomain.co.uk$ [OR]
    RewriteCond %{HTTP_HOST} ^www.mydomain.co.uk$
    RewriteRule ^/?$ "http\:\/\/www\.mydomain\.com\/" [R=301,L]
    RewriteRule ^blog(.*)$ index.php?main_page=blog&$[E=VAR1:$1,QSA,L]
    ErrorDocument 404 /index.php?main_page=page_not_found 
    I have:
    A 301 redirection setup from .co.uk to .com
    A blog integration relevant redirection to /blog
    A zen cart error document redirection

    Pleeese let me know if you see anything out of place, or have any ideas on how this can be improved.

    Thanks

  2. #2
    Join Date
    Mar 2010
    Location
    UK
    Posts
    445
    Plugin Contributions
    0

    Default Re: .htaccess file check please : )

    Your code redirects .co.uk to .com but not when there is an appended port number. It also fails to redirect non-www to www for .com requests, with or without a port number.

    RewriteBase / is the default, so does not need to be specified here.

    Literal periods in RegEx patterns must be escaped.

    The target URL is a literal URL and so no escaping is needed.

    Mass redirects from one domain to a single URL on another domain are frowned upon. Google WebmasterTools now flags these as "Soft 404 Errors" in the Crawl Errors reports. Redirect code also amended to preserve the original part part of the request in the redirect.

    What is supposed to happen if user requests example.co.uk/somepage here? Does that serve content, a 404 error, or should it redirect to .com now? I have set it to redirect to .com with the same path. If you really do need it to redirect to the root then remove the $1 from the code below. If only the root of .co.uk should redirect to the .com then change the (.*) pattern to !. (!. means "blank") as well, like this:

    Code:
    ErrorDocument 404 /index.php?main_page=page_not_found 
    
    Options +FollowSymLinks
    
    RewriteEngine On
    
    #Redirect .co.uk to .com, but should you redirect all
    paths or just the root? Should you use (.*) or .! here?
    # Preserve path in redirect or not? Use $1 or not use $1 here?
    RewriteCond %{HTTP_HOST} ^(www\.)?example\.co\.uk
    RewriteRule (.*) http://www.example.com/$1 [R=301,L]
    
    # Redirect non-www on .com requests to www on .com
    # Redirect MUST preserve originally requested path with (.*) and $1
    RewriteCond %{HTTP_HOST} ^example\.com
    RewriteRule (.*) http://www.example.com/$1 [R=301,L]
    
    # Rewrite /blog URL requests to blog script internal filepath.
    RewriteRule ^blog(.*)$ /index.php?main_page=blog&$1 [E=VAR1:$1,QSA,L]
    I much prefer this:

    Code:
    ErrorDocument 404 /index.php?main_page=page_not_found 
    
    Options +FollowSymLinks
    
    RewriteEngine On
    
    # Redirect any requested non-blank hostname that is not
    # *exactly* www.domain.com to www.domain.com here.
    RewriteCond %{HTTP_HOST} !^(www\.example\.com)?$
    RewriteRule (.*) http://www.example.com/$1 [R=301,L]
    
    # Rewrite /blog URL requests to blog script internal filepath.
    RewriteRule ^blog(.*)$ /index.php?main_page=blog&$1 [E=VAR1:$1,QSA,L]
    I am not sure your final rewrite will work as you expect.

  3. #3
    Join Date
    May 2009
    Posts
    413
    Plugin Contributions
    0

    Default Re: .htaccess file check please : )

    Thanks g1smd!! you really sound like you know your stuff.

    I'll give your edited .htaccess file a go and reply to this thread if I have any probs.

    Cheers

  4. #4
    Join Date
    May 2009
    Posts
    413
    Plugin Contributions
    0

    Default Re: .htaccess file check please : )

    G1smd,

    The /blog redrection works fine.
    The error document redirect works fine.
    Going straight to .com works fine

    However going to http://www.mydomain.co.uk (expecting to be redirected to the .com) goes to http://www.mydomain.co.uk/cgi-sys/defaultwebpage.cgi ?? is it just a case of having to wait a while for it to work or should it work straight away?

    Thanks for your help so far

  5. #5
    Join Date
    Mar 2010
    Location
    UK
    Posts
    445
    Plugin Contributions
    0

    Default Re: .htaccess file check please : )

    Does the root URL of both the .com and .co.uk domains resolve directly to the exact same physical folder inside the server?

    Which folder in the server have you placed the .htaccess file in?

    What can you see when you install Live HTTP Headers for Firefox? Clear the browser cache before testing. What response do you get back, is it 302 or 301? Is there one step or multiple steps.

    It's possible you'll need the RewriteBase after all, if something else is overriding it.

 

 

Similar Threads

  1. v150 Help Please - need help with .htaccess file
    By timb22 in forum General Questions
    Replies: 14
    Last Post: 6 Apr 2015, 08:21 PM
  2. .htaccess file 1.3.9h ?
    By Muzz in forum General Questions
    Replies: 4
    Last Post: 18 Dec 2010, 03:40 AM
  3. .htaccess file
    By mrbert in forum General Questions
    Replies: 0
    Last Post: 22 Apr 2007, 10:06 AM

Posting Permissions

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