问题描述
我刚刚使用XAMPP启动了一个网站,并且大部分事情都得到了解决。但是,当我键入URL“ www.mysite.com”时,它将启动网站,但URL为“ www.mysite.com/website”。 “网站”是我的文件所在的文件夹的名称。如何从地址栏中删除“ /网站”?
.htaccess文件
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.PHP -f
RewriteRule ^(.*)$ $1.PHP [NC,L]
RewriteRule ^$ index.PHP [L]
RewriteRule ^([a-zA-Z0-9]+)?$ user-profile.PHP?user_username=$1 [NC,L]
XAMPP文件夹中htdocs文件夹中的index.PHP文件
<?PHP
if (!empty($_SERVER['HTTPS']) && ('on' == $_SERVER['HTTPS'])) {
$uri = 'https://';
} else {
$uri = 'http://';
}
$uri .= $_SERVER['HTTP_HOST'];
header('Location: '.$uri.'/website/');
exit;
?>
您可能会说我对此很陌生,但是我到处都看过了,我不知道该如何解决。任何帮助表示赞赏。
解决方法
您的索引指向网站目录。
更改
header('Location: '.$uri.'/website/');
到
header('Location: '.$uri);
最好还是直接在.htaccess中检查并调整httpS,因此您不必依靠index.php来调整所使用的协议。
,这不是您通过PHP处理的事情。这是一个Web服务器作业。只需使用ServerName www.mysite.com在apache中创建VirtualHost并添加您的DocumentRoot / path_to_htdocs / website。像这样的东西
<VirtualHost *:80>
DocumentRoot "/path_to_htdocs/website"
ServerName www.mysite.com
</VirtualHost>
<Directory "/path_to_htdocs/website">
AllowOverride All
Options FollowSymLinks MultiViews ExecCGI
Require all granted
</Directory>
,
我不认为虚拟主机是否是您想要的,但我希望此link帮助。干杯