.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

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

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

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:

[LIST]
[] ukratom.com -> www.ukratom.com
[
] ukratom.com/index.html -> www.ukratom.com
[*] www.ukratom.com/index.html -> www.ukratom.com[/LIST]

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:

RewriteRule ^links/(|linktest\\.php|linkser\\.php|home\\.html)$ links/links.php [R=301,L]

I’ll leave the explanation to the tutorial.

Regards,

DK

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.

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