【问题标题】:htaccess static url rewritehtaccess 静态 url 重写
【发布时间】:2012-10-02 23:35:15
【问题描述】:

我正在开发 wordpress 博客,它的 url 模式类似于这样。 localhost/blog/2012/10/12/sample-post/ .

现在我已将 url 模式更新为 localhost/blog/sample-post/

现在,如果有人输入第一个 URL 模式,我需要重定向到第二个 URL 模式,因为我已经向几篇文章提交了具有第一个模式的 URL。

localhost/blog/2012/10/12/sample-post/ 应重定向到 localhost/blog/sample-post/

谁能帮助我提供 htacess 代码?

【问题讨论】:

  • Apaches mod_rewrite 附带了一个出色的文档,其中包括很好的示例,涵盖了您正在寻找的内容。阅读该文档!

标签: .htaccess url mod-rewrite url-rewriting


【解决方案1】:

尝试将这些添加到文档根目录中的 htaccess 文件中。确保它们任何 wordpress 相关规则之前:

RewriteEngine On
RewriteRule ^/?blog/[0-9]{4}/[0-9]{2}/[0-9]{2}/(.*)$ /blog/$1 [L,R=301]

【讨论】:

  • @SyamKumar Works perfectly fine for me,空白 htaccess 文件和新的 apache 安装。
  • 我已经在下面的代码RewriteEngine off <IfModule mod_suphp.c> suPHP_ConfigPath /home/peopleco/public_html/blog/php.ini <Files php.ini> order allow,deny deny from all </Files> </IfModule> # BEGIN WordPress <IfModule mod_rewrite.c> RewriteEngine On RewriteBase /blog/ RewriteRule ^index\.php$ - [L] RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule . /blog/index.php [L] </IfModule> # END WordPress 的顶部添加了上面的代码@ 能否请您指导我确切需要放置的位置。我是使用 htaccess 文件的新手。
猜你喜欢
  • 1970-01-01
  • 2012-11-26
  • 2011-06-02
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多