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

问题描述

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

我希望http://127.0.0.1:8080重定向我http://127.0.0.1:8080/portfolio

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

重定向截图

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

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

标签: phphtml.htaccess

解决方案


与其乱用.htaccess files,为什么不使用 apache 的虚拟主机呢?

在 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/hosts, 或c:\windows\system32\drivers\etc\hosts。您所做的就是像这样添加 fakedomain:

127.0.0.1 fakedomain.com

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

注意:我的项目有一个公用文件夹,我的主要入口点 index.php 所在的位置,这就是为什么您/public在最后看到 DocumentRoot 而 Directory 没有的原因。如果您的不只是调整路径以适应!


推荐阅读