【问题标题】:RewriteRule in htaccess change url without contenthtaccess 中的 RewriteRule 更改 url 没有内容
【发布时间】:2013-10-04 23:05:43
【问题描述】:

我有一个带有 wordpress 的网站,其中包含博客页面。

所以现在这个页面的 Url 类似于 http://abc.com/blog

但我想将此网址转换为 http://blog.abc.com

我在 .htaccess 文件中添加了代码,但重写不起作用。 apache 也开启了重写模式。

有人知道如何更改此网址吗?

我想先在我的本地 wamp 中测试,所以如果可能的话,也请给 localhost 提供建议。

代码是我试过的

Options +FollowSymLinks
RewriteEngine on
RewriteCond %{HTTP_HOST} ^abc\.com/blog [NC] 
RewriteRule http://blog.abc [R=301,L]

【问题讨论】:

  • 如果 Jon 的回答对你有用,那么不要忘记将其标记为已接受。

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


【解决方案1】:

您的规则需要类似于:

RewriteCond %{HTTP_HOST} ^abc\.com$ [NC] 
RewriteRule ^blog/(.*)$ http://blog.abc.com/$1 [R=301,L]

%{HTTP_HOST} 变量只是主机名,没有路径信息是其中的一部分(例如/blog)。 RewriteRule 至少需要 2 个参数:

RewriteRule <pattern to match against the URI> <if matched, rewrite/redirect to this URL> <flags>

【讨论】:

    猜你喜欢
    • 2018-06-16
    • 1970-01-01
    • 2013-09-19
    • 1970-01-01
    • 1970-01-01
    • 2012-11-10
    • 1970-01-01
    • 2015-01-14
    相关资源
    最近更新 更多