You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

WAMP虚拟主机搭配.htaccess出现ERR_CONNECTION_REFUSED问题求助

问题描述

我购买了一个网站,使用Wampserver编辑CSS样式,已创建artwebsite.local虚拟主机,rewrite_module已启用,但加载网站时出现:

ERR_CONNECTION_REFUSED

注:移除网站文件后,使用无.htaccess的简单PHP文件(Hello World)可正常访问。我尝试修改.htaccess但无效,Wampserver配置正常。附上相关配置代码,请求帮助。

.htaccess代码

Options +FollowSymlinks
RewriteEngine on

RewriteBase /

#301 > HTTS with www

#RewriteCond %{HTTP_HOST} !^www\. [OR]
#RewriteCond %{SERVER_PORT} 80
#RewriteRule ^(.*) https://www.domain.fr/$1 [QSA,L,R=301]

#301 > HTTS without www

RewriteCond %{HTTP_HOST} ^www\. [OR]
RewriteCond %{SERVER_PORT} 80
RewriteRule ^(.*) https://artwebsite.local/$1 [QSA,L,R=301]

### Rewriting / request uri to router.php ###

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_URI} ^/$ 
RewriteRule (.*?)$ router.php [QSA,L]

### Rewriting index and general urls ###

RewriteRule ^index.php$ / [R=301]
RewriteRule ^(fr|en|es|it|ru|ar)/index.php$ /$1/ [R=301,L]
RewriteRule ^(fr|en|es|it|ru|ar)/$ router.php?lang=$1 [L]
RewriteRule ^(fr|en|es|it|ru|ar)$ /$1/ [R]
RewriteRule ^(fr|en|es|it|ru|ar)/index.htm$ router.php [L]
RewriteRule ^(fr|en|es|it|ru|ar)/([.-_/a-z0-9]*).php$ router.php?lang=$1 [QSA]

### Rewriting ulrs ads, shops and page by language ###

RewriteRule ^(fr|en|es|it|ru|ar)/[ء-يa-zA-ZA-Яа-я0-9-]+/[ء-يa-zA-ZA-Яа-я0-9-]+-([0-9]+)$ router.php?lang=$1&id=$2 [QSA]
RewriteRule ^(fr|en|es|it|ru|ar)/[ء-يa-zA-ZA-Яа-я0-9-]+$ router.php?lang=$1 [L,QSA]
RewriteRule ^(fr|en|es|it|ru|ar)/[ء-يa-zA-ZA-Яа-я0-9-]+/[ء-يa-zA-ZA-Яа-я0-9-]+$ router.php?lang=$1 [L,QSA]
RewriteRule ^(fr|en|es|it|ru|ar)/[ء-يa-zA-ZA-Яа-я0-9-]+/[ء-يa-zA-ZA-Яа-я0-9-]+/[ء-يa-zA-ZA-Яа-я0-9-]+$ router.php?lang=$1 [L,QSA]
RewriteRule ^(fr|en|es|it|ru|ar)/[ء-يa-zA-ZA-Яа-я0-9-]+/[ء-يa-zA-ZA-Яа-я0-9-]+/[ء-يa-zA-ZA-Яа-я0-9-]+/[ء-يa-zA-ZA-Яа-я0-9-]+$ router.php?lang=$1 [L,QSA]
RewriteRule ^(fr|en|es|it|ru|ar)/[ء-يa-zA-ZA-Яа-я0-9-]+/[ء-يa-zA-ZA-Яа-я0-9-]+/[ء-يa-zA-ZA-Яа-я0-9-]+/[ء-يa-zA-ZA-Яа-я0-9-]+/[ء-يa-zA-ZA-Яа-я0-9-]+$ router.php?lang=$1 [L,QSA]

### Rewriting ulrs ads, shops and page whithout language ###

RewriteRule ^[ء-يa-zA-ZA-Яа-я0-9-]+/[ء-يa-zA-ZA-Яа-я0-9-]+-([0-9]+)$ router.php?id=$1 [QSA]
RewriteRule ^[ء-يa-zA-ZA-Яа-я0-9-]+$ router.php [L]
RewriteRule ^[ء-يa-zA-ZA-Яа-я0-9-]+/[ء-يa-zA-ZA-Яа-я0-9-]+$ router.php [L]
RewriteRule ^[ء-يa-zA-ZA-Яа-я0-9-]+/[ء-يa-zA-ZA-Яа-я0-9-]+/[ء-يa-zA-ZA-Яа-я0-9-]+$ router.php [L]
RewriteRule ^[ء-يa-zA-ZA-Яа-я0-9-]+/[ء-يa-zA-ZA-Яа-я0-9-]+/[ء-يa-zA-ZA-Яа-я0-9-]+/[ء-يa-zA-ZA-Яа-я0-9-]+$ router.php [L]
RewriteRule ^[ء-يa-zA-ZA-Яа-я0-9-]+/[ء-يa-zA-ZA-Яа-я0-9-]+/[ء-يa-zA-ZA-Яа-я0-9-]+/[ء-يa-zA-ZA-Яа-я0-9-]+/[ء-يa-zA-ZA-Яа-я0-9-]+$ router.php [L]

### Rewriting all urls containing a php script name ###

RewriteCond %{HTTP_HOST} ^artwebsite\.local
RewriteCond %{REQUEST_FILENAME} (.*)+\.php
RewriteCond %{REQUEST_URI} !^/(invoices/.*)$
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule (.*?)$ router.php [QSA,L]

ErrorDocument 404 https://artwebsite.local/404

虚拟主机配置

<VirtualHost *:80>
    ServerName artwebsite.local
    DocumentRoot "d:/artweb"
    <Directory  "d:/artweb/">
        Options +Indexes +Includes +FollowSymLinks +MultiViews
        AllowOverride All
        Require local
    </Directory>
</VirtualHost>
问题分析与解决建议

核心问题出在.htaccess的HTTPS重定向规则,你的虚拟主机只配置了HTTP(80端口),没有启用HTTPS(443端口),当访问http://artwebsite.local时,规则强制跳转到https://artwebsite.local,但本地Wampserver没有监听443端口,导致浏览器返回ERR_CONNECTION_REFUSED。

临时解决(先恢复HTTP访问)

  1. 注释掉.htaccess中HTTPS重定向的规则块:
    # #301 > HTTS without www
    # 
    # RewriteCond %{HTTP_HOST} ^www\. [OR]
    # RewriteCond %{SERVER_PORT} 80
    # RewriteRule ^(.*) https://artwebsite.local/$1 [QSA,L,R=301]
    
  2. 同时修改ErrorDocument 404为HTTP地址:
    ErrorDocument 404 http://artwebsite.local/404
    
  3. 清除浏览器缓存(因为301是永久重定向,浏览器会缓存跳转记录),然后重新访问http://artwebsite.local。

永久解决(启用本地HTTPS)

如果需要保留HTTPS重定向,需要给Wampserver配置SSL虚拟主机:

  1. 确保Wampserver的ssl_module已启用(在Apache模块中勾选)。
  2. 在虚拟主机配置文件中添加443端口的配置:
    <VirtualHost *:443>
        ServerName artwebsite.local
        DocumentRoot "d:/artweb"
        SSLEngine on
        SSLCertificateFile "${INSTALL_DIR}/Apache24/conf/ssl.crt/server.crt"
        SSLCertificateKeyFile "${INSTALL_DIR}/Apache24/conf/ssl.key/server.key"
        <Directory  "d:/artweb/">
            Options +Indexes +Includes +FollowSymLinks +MultiViews
            AllowOverride All
            Require local
        </Directory>
    </VirtualHost>
    
    (注:证书文件用Wampserver自带的即可,路径根据你的Wampserver安装目录调整)
  3. 重启Apache服务,然后访问https://artwebsite.local即可。

额外检查

  • 确认router.php文件存在于网站根目录(d:/artweb/),且权限正常。
  • 可以暂时禁用.htaccess中除RewriteEngine外的其他规则,逐步排查是否有其他规则导致的问题。

内容的提问来源于stack exchange,提问作者Rosebud wells

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.24 16:40:08