Puzzel
Puzzel

Reputation: 73

Catch all redirect

This is the htaccess file. I'm wanting to add a catch-all 301 redirect RewriteRule.

This is not working. Any ideas?

RewriteRule ^/(.*)$1 http://www.domain.co.uk/ [R=301,L]

Here are the rest of the rewrites.

enter coOptions +SymlinksIfOwnerMatch +MultiViews
RewriteEngine On 
RewriteBase /

### HTTP > HTTPS & non WWW to WWW version
# RewriteCond %{HTTPS} !on [OR]
RewriteCond %{HTTP_HOST} !^www\. [NC]
# RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s/+(\S*)\sHTTP [NC]
RewriteRule ^ http://www.domain.co.uk/%1 [NE,L,R=301]

### index.php & index to root domain
RewriteRule ^index(?:\.php)? http://www.domain.co.uk/ [R=301,L]

### special rewrite rules for shortened urls ##
RewriteRule ^section(?:\.php)?/(.*)$ /s/$1 [R=301,L]
### To remove section page if 1 which is default for most (unless products span more)
RewriteRule ^s\.php/(.*)/1/(.*) /s/$1/$2 [R=301,L]
RewriteRule ^product(?:\.php)?/(.*)$ /p/$1 [R=301,L]
RewriteRule ^article(?:\.php)?/(.*)$ /a/$1 [R=301,L]
RewriteRule ^discount(?:\.php)/(.*)$ /d/$1 [R=301,L]

### Core Jshop .php removal
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*?)\.php/(.*)$ $1.php?$2 [L,QSA]de here

Redirect 301 /blog http://www.domain.co.uk/a/8/nursing-home-news/

RewriteRule ^/(.*)$1 http://www.domain.co.uk/ [R=301,L] 

Upvotes: 2

Views: 5277

Answers (1)

Amit Verma
Amit Verma

Reputation: 41219

If your rewrite rules are in an htaccess file then you need to remove the leading slash from your rule's pattern as RewriteRule's regex matches against a relative old path starting without a / .

Try :

RewriteRule ^(.*)$ http://www.domain.co.uk/ [R=301,L]

Make sure to clear your browser cache before testing this.

Upvotes: 2

Related Questions