Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/regex/19.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/batch-file/5.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
Regex .htaccess URL将旧链接格式重定向到新链接格式_Regex_Wordpress_Apache_.htaccess - Fatal编程技术网

Regex .htaccess URL将旧链接格式重定向到新链接格式

Regex .htaccess URL将旧链接格式重定向到新链接格式,regex,wordpress,apache,.htaccess,Regex,Wordpress,Apache,.htaccess,最近,我已经将链接格式更改为我自己托管的wordpress博客上的文章,我希望旧书签能够无缝地重定向到新链接,这样读者就不会看到找不到的页面 旧格式为:https://domain.tld/index.php/yyyy/mm/dd/title-of-post 新格式为:https://domain.tld/title-of-post/ 当然,我之所以做出这样的改变,是因为它更好,而且时间对我的博客来说并不是一个真正的因素。我在.htaccess文件中使用Apache的RewriteRule指令,

最近,我已经将链接格式更改为我自己托管的wordpress博客上的文章,我希望旧书签能够无缝地重定向到新链接,这样读者就不会看到找不到的页面

旧格式为:
https://domain.tld/index.php/yyyy/mm/dd/title-of-post

新格式为:
https://domain.tld/title-of-post/

当然,我之所以做出这样的改变,是因为它更好,而且时间对我的博客来说并不是一个真正的因素。我在
.htaccess
文件中使用Apache的
RewriteRule
指令,但在匹配模式时遇到问题。这是
.htaccess
文件的当前状态:

# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php/[0-9]+/[0-9]+/[0-9]/.*?$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>

# END WordPress

甚至

(index)(\\.)(php)(\\/)(\\d)(\\d)(\\d)(\\d)(\\/)(\\d)(\\d)(\\/)(\\d)(\\d)(\\/)((?:[a-z][a-z]+))
最后一次我试着用txt2re


所有这些都没有给我任何运气来匹配我给它的URL。我希望旧链接重定向到新的相应链接

与其修改
.htaccess
不如使用如下重定向插件

https://wordpress.org/plugins/redirection/
它将为您处理所有重定向

这对我和其他许多人都有效。请让我知道这是否适合你

编辑:

对于您的具体情况,以下规则将起作用

RedirectMatch 301 ^/index\.php/([0-9]+)/([0-9]+)/([0-9]+)/(.*)$ http://yourdomain.com/$4
你可以在这里阅读更多关于这条规则的内容


您想将此重定向到?@SufiyanGhori是的,正确您是否尝试过在wordpress管理面板中修改永久链接设置?wordpress应该处理这些问题redirection@SufiyanGhori我有,但没有用。wordpress唯一删除的就是index.php。我甚至已经从htaccess文件中删除了该规则,它仍然只是删除了index.php请查看最新的答案,我已经添加了重定向规则谢谢!天哪,我一直在为这件事绞尽脑汁。重定向插件工作起来就像一个charmCheers!很高兴我帮了忙
https://wordpress.org/plugins/redirection/
RedirectMatch 301 ^/index\.php/([0-9]+)/([0-9]+)/([0-9]+)/(.*)$ http://yourdomain.com/$4