htaccess:将整个子文件夹重定向到根目录

编程入门 行业动态 更新时间:2024-10-13 08:22:03
本文介绍了htaccess:将整个子文件夹重定向到根目录的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我的网站使用Wordpress作为CMS,它已经安装在子文件夹中,但是我将其设置为显示在根域中。基本上, example 显示 example/wordpress 的内容。

My site uses Wordpress as a CMS and it's installed in a subfolder already but I set it up to display on the root domain. Basically, example displays the contents of example/wordpress.

旧的(静态)网站也在子文件夹中,我需要将整个子文件夹(文件夹和所有内容)重定向回根目录,例如将 example/oldwebsite 指向 example 。

The old (static) website was also in a subfolder and I need to redirect that entire subfolder (folder and all contents) back to the root - e.g. point example/oldwebsite to example.

我尝试了很多不同的方法,

I've tried lots of different approaches and I just can't get it to work.

推荐答案

以下解决方案非常容易实现。您得到的是:

The following solution is quite simple to implement. What you get is:

  • wordpress安装在根目录中的某个文件夹中,例如/ wp
  • wp管理员可以通过 http://www.yourdomain.test/wp/wp-admin/访问
  • 站点会在根文件夹中打开,例如: http:// www。 yourdomain.test /
  • wordpress installation in a folder in the root, like in /wp
  • wp admin is accessible via www.yourdomain.test/wp/wp-admin/
  • site opens in root folder like: www.yourdomain.test/

备注

  • 如果不使用永久链接,则可能不需要.htaccess注释;我总是使用永久链接,我想每个人都应该这样做,如果您不编辑.htaccess文件(我不确定),则可能不起作用
  • 如果您不这样做。不知道您在做什么,并且您害怕弄乱事情,在开始之前先将tar / zip压缩为
  • 您可能想使用插件backwpup创建备份启动数据库之前
  • 如果可以选择服务器快照,请立即获取一个快照
  • if you don't use permalinks, you may not need the .htaccess remarks; I always use permalinks, and I think everybody should do so, and then it might not work if you don't edit the .htaccess (I'm not sure)
  • if you don't know what you're doing, and you're afraid to mess things up, tar/zip the wordpress folder before you start
  • you may want to use the plugin backwpup to create a backup of the database before you start
  • if you have the option of a snapshot of your server, take one now

需要什么才能使此工作正常运行:

What you need to get this working:

  • 如果您想要永久链接,请首先使该工作正常;这会创建或需要一个.htaccess文件
  • 将/wp/index.php复制到/index.php,以便复制到您网站的根目录
  • 如果您有.htaccess,请将其也复制到根目录中。
  • 如果您已经在根目录中具有.htaccess,则需要以某种方式进行组合;我现在假设情况并非如此
  • if you want permalinks, get that working first; this creates or needs a .htaccess file
  • copy /wp/index.php to /index.php, so to the root of your site
  • if you have a .htaccess, copy that to the root as well
  • if you have a .htaccess in the root already, you need to combine them somehow; I'll suppose for now that this is not the case

编辑/index.php

Edit /index.php

  • 添加或编辑以下行,这可能是该文件的最后一行
  • 您需要将子目录添加到您的将WordPress安装到路径

  • add or edit the following line, which is probably the last line of this file
  • you need to add the subdirectory to your wordpress installation to the path

require('./wp/wp-blog-header.php');

编辑/.htaccess

Edit /.htaccess

  • 将以下代码添加到.htaccess的末尾或创建新的.htaccess
  • 替换/ wp /以及安装wordpress的目录的名称

  • add the following code to the end of the .htaccess or create a new .htaccess
  • replace /wp/ with the name of the directory where you installed wordpress

# BEGIN WordPress <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> # END WordPress

WordPress设置

Wordpress settings

  • 打开wordpress管理员,然后转到设置>常规
  • 编辑以下两个字段
  • wordpress地址: http://www.yourdomain.test/wp
  • 站点地址: http://www.yourdomain.test/
  • wordpress地址是指向样式表和图像的链接,网站地址是指向其他页面的链接的地方
  • open the wordpress admin, and go to settings > general
  • edit the following two fields
  • wordpress address: www.yourdomain.test/wp
  • site address: www.yourdomain.test/
  • the wordpress address is for links to stylesheets and images, the site address is where links to other pages should go to

重命名wordpress目录

Renaming the wordpress directory

  • 如果您重命名wordpress文件夹,请首先在网站管理员中执行此操作
  • 这将更新数据库值
  • 更新后,管理员将不再工作
  • 然后将其重命名终端或ftp客户端中的目录名称
  • 然后检查所有.htaccess和index.php文件s表示旧名称,然后用新名称替换旧名称
  • if you rename the wordpress folder, do this in the site admin first
  • this updates the database value
  • after the update, the admin won't work anymore
  • then rename the directory name in the terminal or in your ftp-client
  • then check all .htaccess and index.php files for the old name, and replace the old name with the new one

更多推荐

htaccess:将整个子文件夹重定向到根目录

本文发布于:2023-10-31 13:31:52,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1546231.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:根目录   文件夹   重定向   htaccess

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!