Ask your WordPress questions! Pay money and get answers fast! Comodo Trusted Site Seal
Official PayPal Seal

Fix my canonical htaccess code WordPress

  • REFUNDED

I need to configure htaccess to rewrite calls to "robots.txt", "favicon.ico" and various CSS stylesheets which Wordpress is misloading for some reason, but my code doesn't work.

This is the code I wanted to use:

<IfModule mod_rewrite.c>
# Canonical robots.txt
RewriteCond %{REQUEST_URI} !^/robots.txt$ [NC]
RewriteCond %{REQUEST_URI} robots\.txt [NC]
RewriteRule .* http://traveltipsthailand.com/robots.txt [R=301,L]
# Canonical favicon.ico
RewriteCond %{REQUEST_URI} !^/favicon.ico$ [NC]
RewriteCond %{REQUEST_URI} /favicon(s)?\.?(gif|ico|jpe?g?|png)?$ [NC]
RewriteRule (.*) http://traveltipsthailand.com/favicon.ico [R=301,L]
# Canonical stylesheets
RewriteCond %{REQUEST_URI} !^/custom.css$ [NC]
RewriteCond %{REQUEST_URI} /custom\.css [NC]
RewriteRule (.*) http://traveltipsthailand.com/wp-content/themes/GeoPlaces3/custom.css [R=301,L]
RewriteCond %{REQUEST_URI} !^/1-default.css$ [NC]
RewriteCond %{REQUEST_URI} /1-default\.css [NC]
RewriteRule (.*) http://traveltipsthailand.com/wp-content/themes/GeoPlaces3/skins/1-default.css [R=301,L]
RewriteCond %{REQUEST_URI} !^/reset.css$ [NC]
RewriteCond %{REQUEST_URI} /reset\.css [NC]
RewriteRule (.*) http://traveltipsthailand.com/wp-content/themes/GeoPlaces3/library/css/reset.css [R=301,L]
</IfModule>


The rest of my htaccess file looks like this and works just fine:


# Created by Redirection Module: Apache
# Thu, 29 Sep 2011 19:00:35 +0000
# Redirection 2.2.9 - http://urbangiraffe.com/plugins/redirection/

<Files .htaccess,.svn>
order allow,deny
deny from all
</Files>
Options +FollowSymlinks

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{HTTP_HOST} ^www\.traveltipsthailand\.com$ [NC]
RewriteRule ^(.*)$ http://traveltipsthailand.com/$1 [R=301,L]

RewriteCond %{THE_REQUEST} (.*)index\.(php|htm|html)\ HTTP/
RewriteRule ^(.*)index\.(php|html|htm)$ $1 [R=301,NC,L]

</IfModule>

# End of Redirection


# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>



# END WordPress
<Files 403.shtml>
order allow,deny
allow from all
</Files>

RewriteCond %{HTTP_HOST} ^(.*)bangkoktravelthailand.com [NC]
RewriteRule ^(.*)$ http://traveltipsthailand.com/$1 [R=301,L]

#RewriteRule ^(.*)$ http://traveltipsthailand.com/$1 [R=301,L]

#RewriteCond %{HTTP_HOST} ^bangkoktravelthailand\.com$ [OR]
#RewriteCond %{HTTP_HOST} ^www\.bangkoktravelthailand\.com$
#RewriteRule ^/?$ "http\:\/\/traveltipsthailand\.com" [R=301,L]
#RewriteRule ^(.*)$ http://traveltipsthailand.com/$1 [R=301,L]

RewriteCond %{HTTP_HOST} ^1travelthailand\.com$ [OR]
RewriteCond %{HTTP_HOST} ^www\.1travelthailand\.com$
RewriteRule ^/?$ "http\:\/\/traveltipsthailand\.com" [R=301,L]

RewriteRule ^thailand/(.*)$ http://traveltipsthailand.com/$1 [R=301,L]
RedirectMatch 301 /wp-content/themes/geoplaces3/(.*) http://traveltipsthailand.com/wp-content/themes/GeoPlaces3/$1
RedirectMatch 301 /bg/(.*) http://traveltipsthailand.com/$1
RedirectMatch 301 /ko/(.*) http://traveltipsthailand.com/$1
RedirectMatch 301 /bn/(.*) http://traveltipsthailand.com/$1
RedirectMatch 301 /vi/(.*) http://traveltipsthailand.com/$1
RedirectMatch 301 /sv/(.*) http://traveltipsthailand.com/$1
RedirectMatch 301 /zh/(.*) http://traveltipsthailand.com/$1
RedirectMatch 301 /pt/(.*) http://traveltipsthailand.com/$1
RedirectMatch 301 /pl/(.*) http://traveltipsthailand.com/$1
RedirectMatch 301 /nl/(.*) http://traveltipsthailand.com/$1
RedirectMatch 301 /kn/(.*) http://traveltipsthailand.com/$1
RedirectMatch 301 /hu/(.*) http://traveltipsthailand.com/$1
RedirectMatch 301 /hi/(.*) http://traveltipsthailand.com/$1
RedirectMatch 301 /fr/(.*) http://traveltipsthailand.com/$1
RedirectMatch 301 /fi/(.*) http://traveltipsthailand.com/$1
RedirectMatch 301 /de/(.*) http://traveltipsthailand.com/$1
RedirectMatch 301 /da/(.*) http://traveltipsthailand.com/$1
RedirectMatch 301 /hy/(.*) http://traveltipsthailand.com/$1


What I need is a complete htaccess file with the new code inserted, that I can use to replace my current htaccess file without causing any server problems.

Answers (3)

2011-10-11

Abdessamad Idrissi answers:

I don't see why would you would need a rewrite for such things:
* robots.txt should be in the root directory of your website and should be accessible with http://traveltipsthailand.com/robots.txt this is the place where crowlers will look for, so no need for a rewrite condition.
[[LINK href="http://www.google.com/support/webmasters/bin/answer.py?hl=en&answer=156449&from=40360&rd=1"]]Google says [[/LINK]]
<blockquote>You need a robots.txt file only if your site includes content that you don't want search engines to index. If you want search engines to index everything in your site, you don't need a robots.txt file (not even an empty one).</blockquote>

* favicon.ico path is set in the theme header with something like:
<link rel="shortcut icon" href="<?php bloginfo('stylesheet_directory'); ?>/favicon.ico" />

* Same thing for styles:
<link rel="stylesheet" type="text/css" media="all" href="<?php bloginfo( 'stylesheet_url' ); ?>" />

So as you can see, no need for rewrite for such simple things :)

2011-10-11

Alex Sancho answers:

You can acomplish all that rewrites simply using redirections


<IfModule mod_alias.c>
RedirectMatch 301 ^/custom\.css http://domain.tld/dir/dir/custom.css
</IfModule>

2011-10-11

Luis Cordova answers:

try this

<IfModule mod_alias.c>
RedirectMatch 301 ^/robots\.txt http://traveltipsthailand.com/robots.txt
RedirectMatch 301 ^/favicon\.ico http://traveltipsthailand.com/favicon.ico
</IfModule>