Aaron
Aaron

Reputation: 1061

Redirecting to specific page on 404 errors if url contains a string in htaccess

I am trying redirect to a specific page (store page) if a user tries to access a page with a url that contains "/product/" as well as gets a 404 error.

This is what I currently have in my htaccess:

RewriteRule ^/product/.* /store [R=404,L]

What do I need to change to get this working?

Here my current htaccess file:

RewriteEngine On
RewriteCond %{SERVER_PORT} 80
RewriteRule ^(.*)$ www.mydomain.com/$1 [R=301,L]

# Send surplus store 404 errors to the store home page
ErrorDocument 404 /store
RewriteEngine On

RewriteRule ^/?product(/.*)?$ - [R=404,L,NC]

# handle both specific URL redirects for woocommerce
RewriteRule ^/?product-(?:tag|categories|category)/([\w-]+) www.mydomain.com/parts?category=$1 [R=301,L,NC,QSA]

# 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

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

Upvotes: 1

Views: 1373

Answers (1)

anubhava
anubhava

Reputation: 785028

You can use this code in your site root .htaccess:

# BEGIN WordPress
RewriteEngine On
RewriteBase /

# handle both specific URL redirects for woocommerce
RewriteRule ^/?product-(?:tag|categories|category)/([\w-]+) www.mydomain.com/parts?category=$1 [R=301,L,NC,QSA,NE]

RewriteCond %{HTTP_HOST} ^(?:www\.)?mydomain\.com$ [NC]
RewriteRule ^MyAccount\.aspx(/.*)?$ http://online.mydomain.com$1 [R=301,L,NC,NE]

# redirect /product URIs
RewriteRule ^/?product(/.*)?$ /store [R=301,L,NC]

RewriteRule ^index\.php$ - [L]

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]

# END WordPress

Upvotes: 1

Related Questions