Remove subfolder from WordPress URL using htaccess

2019-02-14 08:43发布

问题:

I've moved WordPress into it's own directory as per the instruction found on the WordPress support site.

I've got his working fine but the URL now shows http://www.example.com/subfolder/ but I want it to show without the /subfolder/

I can't seem to get the htaccess to remove the /subfolder/

Here's my current htaccess code

RewriteEngine On
RewriteCond %{HTTP_HOST} ^(www.)?mysite.com$
RewriteRule ^(/)?$ subfolder [L]

回答1:

This should change http://www.mysite.com/subfolder/ to http://www.mysite.com/

RewriteEngine On
RewriteRule ^/subfolder/(.*)$ http://www.mysite.com/$1 [L,R=301]


回答2:

For future reference: I think the answer provided by Hareesh Sivasubramanian is better:

I advice you against messing up the contents of the .htaccess file. Revert the changes that you've made to this file and follow the simple procedue.
1. Login to the admin dashboard.
2. Go to Settings > General
3. In the WordPress Address (URL) field type http://www.example.com/site
4. In the Site Address (URL) field type http://www.example.com
Save the changes and you should be good to go.

(https://stackoverflow.com/a/37346685/1334353)