代码之家  ›  专栏  ›  技术社区  ›  Navnish Bhardwaj

htaccess重定向-wordpress代码冲突

  •  1
  • Navnish Bhardwaj  · 技术社区  · 12 年前

    我想知道是否有好心人能帮助我。

    我在名为“wp”的子目录中创建了一个新的WordPress站点。我不想移动所有的东西(我不完全明白该怎么做),我想简单地重定向主页,即。 http://www.example.com 指向 http://www.example.com/wp/ 对于要从该子目录中加载的所有页面,减去地址行中的/wp/。

    根据web主机的指示,我已将此重定向代码添加到.htaccess文件中:

    # Justhost.com
    # .htaccess main domain to subdirectory redirect
    # Copy and paste the following code into the .htaccess file
    # in the public_html folder of your hosting account
    # make the changes to the file according to the instructions.
    # Do not change this line.
    RewriteEngine on
    # Change example.com to be your main domain.
    RewriteCond %{HTTP_HOST} ^(www.)?example.com
    $
    # Change 'subdirectory' to be the directory you will use for your main domain.
    RewriteCond %{REQUEST_URI} !^/wp/
    # Don't change these line.
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    # Change 'subdirectory' to be the directory you will use for your main domain.
    RewriteRule ^(.*)$ /wp/$1
    # Change example.com to be your main domain again.
    # Change 'subdirectory' to be the directory you will use for your main domain
    # followed by / then the main file for your site, index.php, index.html, etc.
    RewriteCond %{HTTP_HOST} ^(www.)?example.com$
    RewriteRule ^(/)?$ wp/index.php [L]
    

    然而,这是不起作用的,我的网络主机,谁不是很有帮助,告诉我,一些现有的代码生成的WordPress是冲突的。这是.htaccess文件中的现有代码:

    DirectoryIndex index.html index.shtml index.xhtml index.wml index.perl index.pl index.plx index.ppl index.cgi index.jsp index.js index.jp index.php4 index.php3 index.php index.phtml index.htm home.htm default.htm index.fcgi default.html
    # -FrontPage-
    
    IndexIgnore .htaccess */.??* *~ *# */HEADER* */README* */_vti*
    
    <Limit GET POST>
        order deny,allow
        deny from all
        allow from all
    </Limit>
    <Limit PUT DELETE>
        order deny,allow
        deny from all
    </Limit>
    AuthName zsr-art.org.uk
    AuthUserFile /home/zsrarto1/public_html/_vti_pvt/service.pwd
    AuthGroupFile /home/zsrarto1/public_html/_vti_pvt/service.grp
    
    # BEGIN WordPress
    <IfModule mod_rewrite.c>
        RewriteEngine On
        RewriteBase /index.php/
        RewriteRule ^index\.php$ - [L]
        RewriteCond %{REQUEST_FILENAME} !-f
        RewriteCond %{REQUEST_FILENAME} !-d
        RewriteRule . /index.php/index.php [L]
    </IfModule>
    

    我正在使用永久链接,我想知道这是否会导致问题。有人能告诉我冲突在哪里以及如何解决吗?

    1 回复  |  直到 12 年前
        1
  •  1
  •   Justin Iurman    12 年前

    你的 RewriteBase 在里面 /wp/.htaccess 是错误的(所以你的规则是)。

    在该文件中,替换此部分

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

    通过这个

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