SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    SitePoint Enthusiast
    Join Date
    Dec 2008
    Posts
    76
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    .htaccess im trying to set up redirect for canonical url

    i already have some redirects set up becuase i posted some temperary links on a forum to get help with somthing and i wanted those links to be redirected somewere.

    heres what my .htaccess file has already
    Code:
    RewriteEngine on
    RewriteCond %{HTTP_HOST} ^ukratom\.com$ [OR]
    RewriteCond %{HTTP_HOST} ^www\.ukratom\.com$
    RewriteRule ^links\/?$ "http\:\/\/ukratom\.com\/links\/link\.php" [R=301,L]
    
    RewriteCond %{HTTP_HOST} ^ukratom\.com$ [OR]
    RewriteCond %{HTTP_HOST} ^www\.ukratom\.com$
    RewriteRule ^links\/linktest\.php$ "http\:\/\/ukratom\.com\/links\/link\.php" [R=301,L]
    
    RewriteCond %{HTTP_HOST} ^ukratom\.com$ [OR]
    RewriteCond %{HTTP_HOST} ^www\.ukratom\.com$
    RewriteRule ^links\/linkser\.php$ "http\:\/\/ukratom\.com\/links\/link\.php" [R=301,L]
    
    RewriteCond %{HTTP_HOST} ^ukratom\.com$ [OR]
    RewriteCond %{HTTP_HOST} ^www\.ukratom\.com$
    RewriteRule ^links\/home\.html$ "http\:\/\/ukratom\.com\/links\/link\.php" [R=301,L]
    I tryed adding this
    Code:
    RewriteCond %{REQUEST_URI}\/%{HTTP_HOST}/www. ^/+(.+/)?[^.]*[^/]\(/)(([^.]{4,}|[^w.]?[^.][^w.]?[^.]?[^w.]?)..+/(www.)|.*)$ [OR,NC]
    RewriteCond %{HTTP_HOST}/www. ^(/)?(#)?(/)?(([^.]{4,}|[^w.]?[^.][^w.]?[^.]?[^w.]?)..+/(www.))$ [NC]
    RewriteRule ^ http://%6%{HTTP_HOST}%{REQUEST_URI}%2 [L,R=301]
    And i got a server error when i tryed going to my site.

    I want ukratom.com -> www.ukratom.com
    and ukratom.com/index.html -> www.ukratom.com
    and maybe www.ukratom.com/index.html -> www.ukratom.com

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

    I can't begin to tell you how much is wrong with your mod_rewrite code ... so I won't. You might benefit from reading the mod_rewrite tutorial linked in my signature, though, as it contains explanations and sample code. It's helped may members and should help you, too.

    What is usually provided here is a statement of your "specification" for the mod_rewrite code. It looks like you want:



    In addition to:

    • links/, links/linktest.php, links/linkser.php and links/home.html to be redirected to links.php


    First, I always advise against redirecting from the DirectoryIndex to the bare domain as that should generate a loop within Apache as it fetches the DirectoryIndex to serve when the domain (or directory) is requested. Therefore, I'll omit that one (although it can be done using advanced techniques). That leaves merely "force www on the domain" which is already provided as sample code in my signature's tutorial (and echoed through out this board in many posts) so I'll omit that, too.

    The links/ set requires a grouping which is not as common so I'll provide that here:

    Code:
    RewriteRule ^links/(|linktest\.php|linkser\.php|home\.html)$ links/links.php [R=301,L]
    I'll leave the explanation to the tutorial.

    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 Enthusiast
    Join Date
    Dec 2008
    Posts
    76
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    So your saying I should not redirect ukratom.com/index ? Would you like to do all the code for me for $5? I don't have patiants to go over a tutorial right now. I rather not waste my time.

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

    Thanks for the "offer" but that would be tantamount to coding for a script kiddie. I've been here for years to here to help members learn, not to code.

    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
  •