htaccess用永久链接重写wordpress子目录到root

SPR*_*BRN 4 apache .htaccess mod-rewrite

我在目录"wp"中安装了一个wordpress站点.我想将它保存在该文件夹中以便进行维护.Wordpress提供了为永久链接创建htaccess的选项.您可以在下面看到该代码(有效).

我想要的是一个重写者 - 对访问者 - 该网站似乎在根目录中.我要更改重写库,但这不起作用.

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /wp/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /wp/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 . /wp/index.php [L]
</IfModule>
Run Code Online (Sandbox Code Playgroud)

csi*_*csi 12

1)在你的仪表板中,转到设置 - >一般并确保
a)wordpress目录 - > http://mydomain.com/wp
b)站点地址 - > http://mydomain.com

2)将index.php从子目录移动到根目录(MOVE,不要只复制)

3)编辑你的index.php来阅读

/** Loads the WordPress Environment and Template */
require('./wp/wp-blog-header.php');
Run Code Online (Sandbox Code Playgroud)

其中"wp"是您的子目录

4)删除子目录中的任何.htaccess文件

5)将它添加到root中的.htaccess

# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress
Run Code Online (Sandbox Code Playgroud)

在此设置下,您的wordpress安装将位于/ wp /目录中.访问者将使用http://mydomain.com访问您的网站.祝好运.


M'v*_*'vy 2

您对此有何看法:

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^.*$ /wp/index.php [L]


RewriteCond %{REQUEST_URI} !^/wp/.*$
RewriteRule ^(.*)$ /wp/$1 [L]
Run Code Online (Sandbox Code Playgroud)

您将所有不存在的内容重写为 /wp/index.php,并将所有非 /wp/ 文件重写为 /wp/ 等效文件。所以如果你调用index.php它实际上是/wp/index.php