Search code examples
.htaccessmod-rewritehttp-status-code-301

Please take a look at this .htaccess file


I am trying to implement 301's for sub-pages on my site which is hosted on an Apache server (Fasthosts), using Rewrite scripts in the .htaccess file. I have tried to follow many pieces of documentation (infact, I've never had any problems implementing 301's using .htaccess before!) but on this particular website, nothing seems to work.

There is currently a 301 re-direct in there from non-www to www which is working fine. There are also some other snippets using regex which I imagine are for the CMS.

Below is the current state of the .htaccess file. An example of a 301 I'm trying to re-direct is in there (Lines 5 & 6)

Old page: http://www.junkwize.com/home-Garden%20Clearance to New page: http://www.junkwize.com/services/garden-clearance-london

.htaccess file:

RewriteEngine On
RewriteCond %{HTTP_HOST} ^junkwize.com
RewriteRule (.*) http://www.junkwize.com/$1 [R=301]

RewriteCond %{HTTP_HOST} www.junkwize.com/home-Garden%20Clearance
RewriteRule (.*) http://www.junkwize.com/services/garden-clearance-london [R=301]

#Options +FollowSymlinks
RewriteRule ^.htaccess$ — [F]

RewriteRule ^([/admin]+)$ admin/login.php [L]
RewriteRule ^([/admin]+)([/blocks]+)$ admin/login.php [L]

RewriteRule ^([/blocks]+)$ index.php [L]
# RewriteRule ^([^/\.]+)-([^/\.]+)-([^/\.]+)$ index.php?main=$1&id=$2&menu=$3 [L]
RewriteRule ^([/deals]+)-([^/\.]+)$ index.php?main=$1&id=$2 [L]

# RewriteRule ^([^/\.]+)-([^/\.]+)$ index.php?main=$1&leftmain=$2 [L]
RewriteRule ^([^/\.]+)/([^/\.]+)$ index.php?main=$1&leftmain=$2 [L]
RewriteRule ^([^/\.]+)$ index.php?main=$1 [L]

Any help would be much appreciated.

Many thanks.


Solution

  • This code is faulty and is not going to work:

    RewriteCond %{HTTP_HOST} www.junkwize.com/home-Garden%20Clearance
    RewriteRule (.*) http://www.junkwize.com/services/garden-clearance-london [R=301]
    

    Reason is that RewriteCond %{HTTP_HOST} can only match host name. Replace that code with this:

    RewriteRule ^home-Garden\ Clearance/?$ /services/garden-clearance-london [R=301,L,NC]