Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 13 of 13
  1. #1
    Regular Coder
    Join Date
    Oct 2009
    Posts
    478
    Thanks
    7
    Thanked 3 Times in 3 Posts

    my rewritecond is not redirecting correctly

    I am unsure how to set the htaccess correctly so it forwards visitors like so.

    If someone types. www.sitename.co.uk/somefolder/somepage.html
    I am wanting to take them instead to...
    www.sitename.com/somefolder/somepage.html

    The code below in this case takes the visitor to...

    www.sitename.comsomefolder/somepage.html

    with a missing / after the .com

    What is the correct way to redirect them to the right page ? or any other link on the site.

    www.sitename.co.uk/somefolder2/somepage2.html
    or otherwise

    Code:
    RewriteEngine on
    
    RewriteCond %{HTTP_HOST} ^sitename.co.uk$ [OR]
    RewriteCond %{HTTP_HOST} ^www.sitename.co.uk$ [OR]
    RewriteCond %{HTTP_HOST} ^sitename.com$
    RewriteRule ^(.*)$ "http\:\/\/www.sitename\.com$1" [R=301,L]

  • #2
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,994
    Thanks
    4
    Thanked 2,662 Times in 2,631 Posts
    Looks to me that you are simply missing your / in there.
    PHP Code:
    header('HTTP/1.1 420 Enhance Your Calm'); 
    Been gone for a few months, and haven't programmed in that long of a time. Meh, I'll wing it ;)

  • #3
    Regular Coder
    Join Date
    Oct 2009
    Posts
    478
    Thanks
    7
    Thanked 3 Times in 3 Posts
    on this line...

    RewriteRule ^(.*)$ "http\:\/\/www.sitename\.com/$1" [R=301,L]

    I did try that but it still did the same thing and join the url together as though there was no / after the .com

  • #4
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,994
    Thanks
    4
    Thanked 2,662 Times in 2,631 Posts
    Remove the escapes and see if that makes the difference. You cannot pattern match the rewrite condition that you are going to, so just use htt://www.sitename.com/$1 and see if that does the trick.
    PHP Code:
    header('HTTP/1.1 420 Enhance Your Calm'); 
    Been gone for a few months, and haven't programmed in that long of a time. Meh, I'll wing it ;)

  • #5
    Regular Coder
    Join Date
    Oct 2009
    Posts
    478
    Thanks
    7
    Thanked 3 Times in 3 Posts
    that did the trick. thanks.

    I also have another problem...

    I have three domains

    dom1.com and dom1.co.uk
    dom2.com and dom2.co.uk
    dom3.com and dom3.co.uk

    would I be right in doing this...
    Code:
    RewriteCond %{HTTP_HOST} ^sitename1.co.uk$ [OR]
    RewriteCond %{HTTP_HOST} ^www.sitename1.co.uk$ [OR]
    RewriteCond %{HTTP_HOST} ^sitename1.com$
    RewriteRule ^(.*)$ "http://www.sitename1.com/$1" [R=301,L]
    
    RewriteCond %{HTTP_HOST} ^sitename2.co.uk$ [OR]
    RewriteCond %{HTTP_HOST} ^www.sitename2.co.uk$ [OR]
    RewriteCond %{HTTP_HOST} ^sitename2.com$
    RewriteRule ^(.*)$ "http://www.sitename2.com/$1" [R=301,L]
    
    RewriteCond %{HTTP_HOST} ^sitename3.co.uk$ [OR]
    RewriteCond %{HTTP_HOST} ^www.sitename3.co.uk$ [OR]
    RewriteCond %{HTTP_HOST} ^sitename3.com$
    RewriteRule ^(.*)$ "http://www.sitename3.com/$1" [R=301,L]
    to have each .co.uk forward to the .com domain and still have the end of the url after the .com be the same as what it was after the .co.uk... ?

  • #6
    Regular Coder
    Join Date
    Oct 2009
    Posts
    478
    Thanks
    7
    Thanked 3 Times in 3 Posts
    ok not working again, seems like it does not like it when i have spaces in the url, even if i place %20 in place of them. otherwise it works ok and the multiple rewrite works too.

    but not if there are spaces. How do I get around that ?

  • #7
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,994
    Thanks
    4
    Thanked 2,662 Times in 2,631 Posts
    Try adding the NE flag. Not sure if that will make the difference or not.
    I always avoid spaces in the URL's since they are so problematic >.>
    PHP Code:
    header('HTTP/1.1 420 Enhance Your Calm'); 
    Been gone for a few months, and haven't programmed in that long of a time. Meh, I'll wing it ;)

  • #8
    Regular Coder
    Join Date
    Oct 2009
    Posts
    478
    Thanks
    7
    Thanked 3 Times in 3 Posts
    sorry ne flag ?

    i goggled but still not able to work it out

  • #9
    Regular Coder
    Join Date
    Oct 2009
    Posts
    478
    Thanks
    7
    Thanked 3 Times in 3 Posts
    ah i may have found out why this would not work before... I have upper case letters in my urls... how to I prevent my url from being taken down to lower case by the mod re_write ?

  • #10
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,994
    Thanks
    4
    Thanked 2,662 Times in 2,631 Posts
    I wouldn't think that it would recase it; I would expect if I put in site.com/MyPath Here and redirected it, that it would end up as site2.com/MyPath Here as well.
    So with yours, you would type in site.co.uk/My Path Here and its redirecting to site.com/my path here?
    I won't be able to test this out until I get home tonight.
    PHP Code:
    header('HTTP/1.1 420 Enhance Your Calm'); 
    Been gone for a few months, and haven't programmed in that long of a time. Meh, I'll wing it ;)

  • #11
    Regular Coder
    Join Date
    Oct 2009
    Posts
    478
    Thanks
    7
    Thanked 3 Times in 3 Posts
    Quote Originally Posted by Fou-Lu View Post
    I wouldn't think that it would recase it; I would expect if I put in site.com/MyPath Here and redirected it, that it would end up as site2.com/MyPath Here as well.
    So with yours, you would type in site.co.uk/My Path Here and its redirecting to site.com/my path here?
    I won't be able to test this out until I get home tonight.
    Yes that's what happening here. Very odd.

  • #12
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,994
    Thanks
    4
    Thanked 2,662 Times in 2,631 Posts
    I can't replicate this behaviour. Are you sure its not another rule you have taking it over?
    When I do this with an htaccess:
    Code:
    RewriteRule news/?(.*) rewritetest.php?$1 [L]
    RewriteCond %{HTTP_HOST} ^127.0.0.1$
    RewriteRule ^(.*)$ http://localhost/$1 [R=301,L]
    And provide a url of: http://127.0.0.1/news/With Upper Case Words, I end up with http://localhost/rewritetest.php?With%20Upper%20Case%20Words, which is what I would expect.
    PHP Code:
    header('HTTP/1.1 420 Enhance Your Calm'); 
    Been gone for a few months, and haven't programmed in that long of a time. Meh, I'll wing it ;)

  • #13
    Regular Coder
    Join Date
    Oct 2009
    Posts
    478
    Thanks
    7
    Thanked 3 Times in 3 Posts
    Quote Originally Posted by Fou-Lu View Post
    I can't replicate this behaviour. Are you sure its not another rule you have taking it over?
    When I do this with an htaccess:
    Code:
    RewriteRule news/?(.*) rewritetest.php?$1 [L]
    RewriteCond %{HTTP_HOST} ^127.0.0.1$
    RewriteRule ^(.*)$ http://localhost/$1 [R=301,L]
    And provide a url of: http://127.0.0.1/news/With Upper Case Words, I end up with http://localhost/rewritetest.php?With%20Upper%20Case%20Words, which is what I would expect.
    All thats in my htaccess file is that and three others all very similar, but all working apart from this case changing. The errordocument and the default suPHP_ConfigPath for some of Softaculous.

    Redirects in cPanel shows that all my .co.uk domains goes to their .com counterparts.

    Is there some setting that may be lowering the case of redirects, if it is not a problem with htaccess ?


  •  

    Posting Permissions

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