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

Php 如果url在htaccess中包含字符串,则重定向到404错误上的特定页面,php,.htaccess,Php,.htaccess,如果用户试图访问包含“/product/”url的页面,并且收到404错误,我将尝试重定向到特定页面(存储页面) 这是我目前在htaccess中拥有的内容: 重写规则^/product/*/store[R=404,L] 我需要改变什么才能让它工作 这里是我当前的htaccess文件: RewriteEngine On RewriteCond %{SERVER_PORT} 80 RewriteRule ^(.*)$ www.mydomain.com/$1 [R=301,L] # Send sur

如果用户试图访问包含“/product/”url的页面,并且收到404错误,我将尝试重定向到特定页面(存储页面)

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

重写规则^/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]
重新编写引擎打开
重写cond%{SERVER_PORT}80
重写规则^(.*)$www.mydomain.com/$1[R=301,L]
#将剩余存储404错误发送到存储主页
错误文档404/存储
重新启动发动机
重写规则^/?产品(/.*)-[R=404,L,NC]
#处理woocommerce的两个特定URL重定向
重写规则^/?产品-(?:标记|类别|类别)/([\w-]+)www.mydomain.com/parts?类别=$1[R=301,L,NC,QSA]
#开始WordPress
重新启动发动机
重写基/
重写规则^index\.php$-[L]
重写cond%{REQUEST_FILENAME}-F
重写cond%{REQUEST_FILENAME}-D
重写规则/index.php[L]
#结束WordPress
RewriteCond%{HTTP_HOST}^mydomain\.com$[或]
重写cond%{HTTP_HOST}^www\.mydomain\.com$
重写规则^MyAccount\.aspx\/?(.*)$“http\:\/\/online\.mydomain\.com\/$1”[R=301,L]

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

感谢您的回答,但我的这一方无法使用此url www.mydomain.com/product/t414751r-exchdpf-filterok,我已使用我的htaccess更新了问题,我不得不删除一些https://Ah 这是wordpress:(您必须通过theme的404处理程序进行不同的操作,可能是WP rewrite APIOr,或者如果您可以使用
301/302
完全重定向到
/store
,那么我们可以通过
RewriteRule
Ya进行操作,不幸的是,这是wordpress。我想我可以使用301/302重定向