301将一个目录中的html文件重定向到Wordpress中的自定义帖子类型

时间:2014-07-01 07:50:37

标签: html wordpress .htaccess redirect

我正在努力解决htaccess规则,将html文件的请求重定向到自定义帖子。我在这里和其他地方看过,差不多到了那里。

我想将仅限 mydomain.com/profiles/.html重定向到mydomain.com/name_profile /

mydomain.com/profiles/smith.html到mydomain.com/name_profiles/smith。有大约900个html文件需要重定向,它们都包含在这个目录中。我需要正确关联的域中的其他html文件。

我目前有

RedirectMatch 301  ^/([^/]+)/([^/.]+)\.html$ /$1/$2/
RedirectMatch 301  ^/([^/]+)/([^/]+)/([^/.]+)\.html$ /$1/$2/$3/

但是这会重定向所有html页面,而不仅仅是profile目录中的那些页面。

我是htaccess的新手,已经找到了几个教程,但没有一个我能理解的水平,所以非常欢迎任何帮助。

2 个答案:

答案 0 :(得分:0)

将此规则放在RewriteEngine On行:

下方
RewriteRule ^profiles/([^.]+)\.html$ /name_profiles/$1 [L,NC,R=301]

答案 1 :(得分:0)

使用此规则:

RewriteEngine On
RewriteRule ^profiles/([^.]+)\.html/? name_profiles/$1 [DPI,L,R]

或者更好的是,删除您的RewriteMatch规则并替换为:

RewriteEngine On
RewriteRule ^([^/]+)/([^/.]+)\.html/? $1/$2 [DPI,L,R]
RewriteRule ^([^/]+)/([^/]+)/([^/.]+)\.html/? $1/$2/$3 [DPI,L,R]

这假设mod_rewrite 已为htaccess文件激活。 如果您不确定,要检查是否安装了mod_rewrite,请查看phpinfo();输出中已安装模块的列表 默认情况下,不为htaccess文件启用mod_rewrite。如果您要管理自己的服务器,请打开httpd.conf 并确保webroot目录块包含以下行之一:AllowOverride FileInfoAllowOverride All