php - .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:8080或http://127.0.0.1:8080时,它会将我重定向到XAMPP Dashboard。
.htaccess
我应该把文件放在哪里。在htdocs
文件夹中还是在其他地方?如何将IP 地址重定向到特定文件夹而不是XAMPP Dashboard?
解决方案
与其乱用.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 没有的原因。如果您的不只是调整路径以适应!
推荐阅读
- git - 获取 terraform 配置后的 Terraform 计划
- azure - Delta 湖 RESTORE 问题(Databricks)
- javascript - 需要关于按钮客户端单击功能调用按钮单击方法的javasript解决方案
- asp.net-core - 如何在 asp.net core mvc 中制作级联下拉菜单?
- html - CSS/HTML 自定义框架/效果
- react-native - 从另一个屏幕调用函数时 useState 数组未更新
- java - android java中的CameraX面部过滤器
- reactjs - 在分页反应表中选择行问题
- cypress - 赛普拉斯 response.body 二进制 SHA256 在使用 CryptoJS 时有所不同
- c - vscode中使用scanf(c语言)