繁体   English   中英

.htaccess将XAMPP仪表板(http:// localhost:8080)或特定IP地址(http://127.0.0.1:808080)重定向到特定文件夹

[英].htaccess redirect XAMPP Dashboard (http://localhost:8080 ) or specific IP address (http://127.0.0.1:808080) to specific folder

我需要将具有特定IP地址的访问者重定向到服务器中的特定文件夹。

我想http://127.0.0.1:8080重定向我http://127.0.0.1:8080/portfolio

但是,当我在浏览器中放置http:// localhost:8080http://127.0.0.1:8080时 ,它会将我重定向到XAMPP Dashboard

Screenshot of redirection

  1. 我应该在哪里放置.htaccess文件。 htdocs文件夹中还是其他地方?

  2. 如何将IP地址重定向到特定文件夹而不是XAMPP仪表板

为什么不使用apache的虚拟主机,而不是搞乱.htaccess files

在Apache conf文件中,取消注释http-vhosts.conf中所需的行。 然后使用以下内容编辑该文件:

<VirtualHost *:80>
    DocumentRoot "/your/htdocs/sitename/public"
    ServerName fakedomain.com
    ErrorLog "path/to/error_log"
    <Directory "/your/htdocs/sitename">
        DirectoryIndex index.php
        FallbackResource /index.php
        Options -Indexes +FollowSymLinks
        AllowOverride all
        Require all granted
    </Directory>
</VirtualHost>

编辑之后,您需要编辑/etc/hostsc:\\windows\\system32\\drivers\\etc\\hosts 您所要做的就是像这样添加fakedomain:

127.0.0.1 fakedomain.com

现在,当您重新启动apachea和浏览器时,您应该能够浏览到http://fakedomain.com ,它将转到正确的项目。

注意:我的项目在我的主要入口index.php所在的位置有一个公用文件夹,这就是为什么您看到DocumentRoot的末尾带有/public却没有Directory的原因。 如果您不只是调整适合自己的道路!

暂无
暂无

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

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