【问题标题】:Extract URL for Redirect提取用于重定向的 URL
【发布时间】:2017-02-14 21:58:42
【问题描述】:

我已经建立了一个包含食谱的网站,但在将旧网址迁移到新网址的过程中,我遇到了问题。

https://example.com/recipes/cheesy-baked-tacos/

这是我的旧 URL 结构,在 wordpress 站点中,我需要提取 URL “cheesy-baked-tacos”的最后一部分,并在我用于食谱页面的模板中处理它。

现在,当我点击 URL 时,即使食谱页面已经设置,它也会进入 404 页面。

我尝试遵循 htaccess 规则但没有成功

RewriteBase /
RewriteRule ^recipes/(.*)$ index.php?l=$1

提前致谢。

完整的 htaccess 文件如下所示

# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^recipes/(.*)$ index.php?l=$1
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress

【问题讨论】:

  • 你启用了 RewriteEngine 吗?要启用它,您需要在 htaccess 顶部使用 RewriteEngine on
  • 你的规则在我看来没问题。你要去哪个网址?
  • 引导我到 404 页面

标签: php wordpress apache .htaccess mod-rewrite


【解决方案1】:
you should check your permalink change to starts with id to without query string
dont change htacces file
you just change permalink in new server
https://example.com/recipes/cheesy-baked-tacos/
this is your old url and has permalink set without query string 

new url https://example.com/recipes/cheesy-baked-tacos/id=50 just like
thats why your code have error

【讨论】:

  • 不,我们的社交媒体网络中已经有数千个这样的旧网址。我们无法一一更新它们以包含 id。我只需要一种方法来自动化这个过程。
【解决方案2】:

设法解决了 301 重定向问题。如果它对某人有帮助,这就是我使用的。

# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^recipes/(.*)$ recipe/?post_name=$1 [L,R=301,NC]
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-09-30
    • 2014-04-07
    • 1970-01-01
    • 1970-01-01
    • 2016-08-20
    相关资源
    最近更新 更多