Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/wordpress/13.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Wordpress Apache 301重定向原始URL包含特殊字符的位置_Wordpress_Apache_.htaccess_Mod Rewrite_Redirect - Fatal编程技术网

Wordpress Apache 301重定向原始URL包含特殊字符的位置

Wordpress Apache 301重定向原始URL包含特殊字符的位置,wordpress,apache,.htaccess,mod-rewrite,redirect,Wordpress,Apache,.htaccess,Mod Rewrite,Redirect,我正在寻找一些.htaccess重定向或重写规则帮助 我的客户有一个网站,它的URL格式很差,Google Web工具将其报告为404错误,例如: /calendar-of-events/wanda-hollberg’s-fused-glass-jewelry-trunk-show/ /dining club.cfm 注意到那个糟糕的撇号“'”了吗 下面是另一个例子: /calendar-of-events/wanda-hollberg’s-fused-glass-jewelry-trun

我正在寻找一些.htaccess重定向重写规则帮助

我的客户有一个网站,它的URL格式很差,Google Web工具将其报告为404错误,例如:

/calendar-of-events/wanda-hollberg’s-fused-glass-jewelry-trunk-show/
/dining club.cfm
注意到那个糟糕的撇号“'”了吗


下面是另一个例子:

/calendar-of-events/wanda-hollberg’s-fused-glass-jewelry-trunk-show/
/dining club.cfm
注意空格“?”


还有一个例子:

/calendar-of-events/“a-viticultural-voyage”-wine-dinnerstar/
注意不正确的引号“,”和“?”


我尝试过重定向规则,但没有成功,例如UTF-8编码

Redirect 301 /calendar-of-events/wanda-hollberg%E2%80%99s-fused-glass-jewelry-trunk-show/ /calendar-of-events/
Redirect 301 /dining%20club.cfm /cuisine/
Redirect 301 /calendar-of-events/%E2%80%9Ca-viticultural-voyage%E2%80%9D-wine-dinnerstar/ /calendar-of-events/
以及尝试使用RegExp

Redirect 301 /calendar-of-events/wanda-hollberg(.*)s-fused-glass-jewelry-trunk-show/ /calendar-of-events/
Redirect 301 /dining(.*)club.cfm /cuisine/
Redirect 301 /calendar-of-events/(.*)a-viticultural-voyage(.*)-wine-dinnerstar/ /calendar-of-events/
但是我猜RegExp在重定向中不起作用

所以我尝试了一个重写规则,但仍然没有成功

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule (.*)/calendar-of-events/wanda-hollberg(.*)s-fused-glass-jewelry-trunk-show/$ /calendar-of-events/ [R=301,L]
</IfModule>

重新启动发动机
重写基/
重写规则(.*)/活动日历/wanda hollberg(.*)s-fused-glass-jewelry-trunk-show/$/活动日历/[R=301,L]

请告知,我遗漏了什么或做错了什么

我应该使用重定向还是重写规则?我该怎么写规则呢


我还应该注意到,这是一个WordPress网站,因此.htaccess文件也有

# 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

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /

# redirect none-www to www
RewriteCond %{HTTP_HOST} ^domain\.com$
RewriteRule (.*) http://www.domain.com/$1 [R=301,L]

# redirect m. to www
RewriteCond %{HTTP_HOST} ^m\.domain\.com$
RewriteRule (.*) http://www.domain.com/$1 [R=301,L]

# redirect legacy. to www
RewriteCond %{HTTP_HOST} ^legacy\.domain\.com
RewriteRule (.*) http://www.domain.com/$1 [R=301,L]

</IfModule>
#开始WordPress
重新启动发动机
重写基/
重写规则^index\.php$-[L]
重写cond%{REQUEST_FILENAME}-F
重写cond%{REQUEST_FILENAME}-D
重写规则/index.php[L]
#结束WordPress
重新启动发动机
重写基/
#将无www重定向到www
重写cond%{HTTP_HOST}^domain\.com$
重写规则(.*)http://www.domain.com/$1[R=301,L]
#重定向m。到www
重写cond%{HTTP_HOST}^m\.domain\.com$
重写规则(.*)http://www.domain.com/$1[R=301,L]
#重定向遗产。到www
重写cond%{HTTP_HOST}^legacy\.domain\.com
重写规则(.*)http://www.domain.com/$1[R=301,L]


非常感谢您的建议和努力。干杯。

你需要去掉规则中的斜杠。如果要匹配对
/calendar
的请求,正则表达式需要以
^calendar
开头,不带前导斜杠。当与htaccess文件中的规则进行匹配时,mod_rewrite会删除斜杠

正如Justin Iurman所提到的,您的所有重定向必须在wordpress路由规则之前。规则的顺序非常重要,路由规则会吞噬所有请求,从而使重定向中断

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /

# redirect none-www to www
RewriteCond %{HTTP_HOST} ^domain\.com$
RewriteRule (.*) http://www.domain.com/$1 [R=301,L]

# redirect m. to www
RewriteCond %{HTTP_HOST} ^m\.domain\.com$
RewriteRule (.*) http://www.domain.com/$1 [R=301,L]

# redirect legacy. to www
RewriteCond %{HTTP_HOST} ^legacy\.domain\.com
RewriteRule (.*) http://www.domain.com/$1 [R=301,L]

RewriteRule ^calendar-of-events/wanda-hollberg`s-fused-glass-jewelry-trunk-show/$ /calendar-of-events/ [R=301,L]
RewriteRule ^dining\ club.cfm /cuisine/ [R=301,L]
RewriteRule ^calendar-of-events/\“a-viticultural-voyage\”-wine-dinnerstar/ /calendar-of-events/ [R=301,L]
</IfModule>

# 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

(.*)
分组在
重定向中不起作用的原因是该指令不使用正则表达式。您必须使用
RedirectMatch
。但无论如何,你还是要坚持用mod_重写。由于您有wordpress规则,mod rewrite和mod alias最终都会应用于相同的请求,这将中断您的重定向。

首先要将您的规则置于WP规则之上(否则,它们将永远不会执行)。非常感谢您提供的额外细节…我学到了很多,这解决了我的问题。