【问题标题】:.htaccess and WordPress.htaccess 和 WordPress
【发布时间】:2017-01-30 23:31:35
【问题描述】:

我的 WordPress 出现问题 我的 WordPress 安装在假定为 blog.lupinedream.com 的子域上。我的提供商将那里的请求转发到/public_html/blog/ 中的目录。我的登录页面位于www.lupinedream.com,它指向两个不同的子域供您选择:forumsblog。有了这些信息,问题就来了。

什么是正确的.htaccess 配置来自动转发所有请求(包括GETPOSTPUT、...等等。针对http://www.lupinedream.com/blogblog.lupinedream.com

我问的原因是因为 WordPress 在 Settings -> General 中要求 Site URLWordPress URL 以允许将 WordPress 安装在子目录中,但我的行为很奇怪当我使用我当前的配置(损坏的图像、GET 和 POST 不起作用)时,当 WordPress 尝试在内部将请求指向 http://www.lupinedream.com/blog/ 时。在地址栏中,我注意到我的 URL 也变成了 foobar。


配置:

/public_html/.htaccess

Options ExecCGI Includes IncludesNOEXEC SymLinksIfOwnerMatch -Indexes

## File Type Specifications
AddType text/html .html .htm .xml
AddType text/plain .txt .text .doc .md .nfo .info
<IfModule mod_cgi.c>
    AddHandler cgi-script .cgi .pl .py .jsp .asp .shtml .sh 
    AddType cgi-script .cgi .pl .py .jsp .asp .shtml .sh
</IfModule>
<iFModule mod_php.c>
    AddHandler application/x-httpd-php70 .php .php3 .php4 .php5 .php53 .phtml .tpl .html
    AddType application/x-httpd-php70 .php .php3 .php4 .php5 .php53 .phtml .tpl .html
</IfModule>
DirectoryIndex index.html index.php under_construction.html

## Query limits
<Limit GET POST>
    Order deny,allow
    Deny from All
    Allow from All
</Limit>
<Limit PUT DELETE>
    Order deny,allow
    Deny from All
    Allow from localhost
</Limit>

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /blog/index.php [L]
</IfModule>

/public_html/blog/.htaccess

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /blog/index.php [L]
</IfModule>

WordPress 设置>常规

Site URL : http://www.lupinedream.com/

WordPress URL : http://blog.lupinedream.com/

【问题讨论】:

    标签: php wordpress .htaccess mod-rewrite


    【解决方案1】:

    假设blog.example.comwww.example.com/blog 下面的结构是相同的,重定向看起来像

    RewriteRule ^blog/(.*)$ http://blog.example.com/$1 [R,L]
    

    由于您的提供商已经将blog.example.com 重写为/blog/...,您应该能够删除/public_html/.htaccess 中现有的RewriteRules

    【讨论】:

    • 我在这里使用了子域示例:link,但重定向似乎不起作用。如果我去blog.example.com 我可以查看页面源代码。从 http://www.example.com/blog 访问时,所有 blog.example.com 的内容在 href 中都有两个“//”。这似乎也会以某种方式影响外部链接,例如 google。
    • 是的,但是您的 Wordpress 站点位于 /blog 之下,不是吗?而且你在/blog/.htaccess 中也已经有了这个sn-p。
    • 你把重写规则放入/public_html/.htaccess了吗?
    • 不,我把它放在/public_html/blog/.htaccess。我的错。但我发现我的 CNAME 记录在我的注册商门户中无法正常工作,所以我也在进行注册商转移以确保它 100% 正常工作。我需要从 DynDNS 转移它。
    猜你喜欢
    • 1970-01-01
    • 2020-12-08
    • 1970-01-01
    • 2014-04-08
    • 1970-01-01
    • 2012-02-03
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多