如果url在htaccess中包含字符串,则重定向到404错误的特定页面

时间:2017-04-20 17:56:12

标签: php .htaccess

如果用户尝试访问包含" / product /"的网址的页面,我正在尝试重定向到特定页面(商店页面)。以及获得404错误。

这是我目前在我的htaccess中所拥有的:

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

我需要做些什么来改变它?

这是我目前的htaccess文件:

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]

1 个答案:

答案 0 :(得分:1)

您可以在站点根目录中使用此代码.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