简体   繁体   English

使用htaccess从WordPress URL中删除子文件夹

[英]Remove subfolder from WordPress URL using htaccess

I've moved WordPress into it's own directory as per the instruction found on the WordPress support site. 我根据WordPress支持网站上的说明将WordPress移动到了自己的目录中。

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/ 我的工作正常,但URL现在显示http://www.example.com/subfolder/但是我希望它显示没有/subfolder/

I can't seem to get the htaccess to remove the /subfolder/ 我似乎无法获取htaccess删除/subfolder/

Here's my current htaccess code 这是我目前的htaccess代码

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

This should change http://www.mysite.com/subfolder/ to http://www.mysite.com/ 这应该将http://www.mysite.com/subfolder/更改为http://www.mysite.com/

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

For future reference: I think the answer provided by Hareesh Sivasubramanian is better: 供将来参考:我认为Hareesh Sivasubramanian提供的答案更好:

I advice you against messing up the contents of the .htaccess file. 我建议你不要弄乱.htaccess文件的内容。 Revert the changes that you've made to this file and follow the simple procedue. 还原您对此文件所做的更改,并按照简单的过程进行操作。
1. Login to the admin dashboard. 1.登录管理仪表板。
2. Go to Settings > General 2.转到设置>常规
3. In the WordPress Address (URL) field type http://www.example.com/site 3.在WordPress地址(URL)字段中键入http://www.example.com/site
4. In the Site Address (URL) field type http://www.example.com 4.在“站点地址(URL)”字段中,键入http://www.example.com
Save the changes and you should be good to go. 保存更改,你应该好好去。

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM