繁体   English   中英

部署服务器忽略.htaccess文件

[英]Deployment Server Ignores .htaccess File

root上的.htaccess文件如下所示:

RewriteEngine on
RewriteBase /
options +FollowSymLinks
RewriteRule ^en/users/profile/?$ [F,NC]
RewriteRule ^en/users/profile/?([0-9]+)?/?$ en/user/index.php?id=$1
RewriteRule ^en/users/profile/([0-9]+)/photo/? en/user/index.php?pageID=photoEdit&id=$1

RewriteCond %{HTTP_REFERER} !^http://example\.ge/?.*$ [NC]
RewriteCond %{HTTP_REFERER} !^http://example\.dev/?.*$ [NC]
RewriteCond %{HTTP_REFERER} !^http://localhost/?.*$ [NC]
RewriteRule \.(gif|jpe?g|png|bmp)$ - [F,NC]

它可以在本地主机上完美地重新路由,但在部署服务器上会被忽略! 这是phpinfo(); 服务器!

这是etc文件夹: etc文件夹

您可能没有在服务器上启用.htaccess文件。 看看AllowOverride指令。 您可以将这样的内容添加到<VirtualHost>的文档根<Directory><Directory>块中:

AllowOverride all
 RewriteRule ^en/users/profile/?$ [F,NC] 

这不是导致.htaccess文件被忽略的原因(其他答案已经为此提供了解决方案,关于检查服务器配置中的AllowOverride指令),但是您在上述指令中缺少有效的替换 /en/users/profile/的请求不会被禁止,并且可能只会导致错误/ 404。

它需要是这样的:

 RewriteRule ^en/users/profile/?$ - [F,NC]

(只有一个连字符用于替换 。)

 RewriteCond %{HTTP_REFERER} !^http://example\\.ge/?.*$ [NC] RewriteCond %{HTTP_REFERER} !^http://example\\.dev/?.*$ [NC] RewriteCond %{HTTP_REFERER} !^http://localhost/?.*$ [NC] RewriteRule \\.(gif|jpe?g|png|bmp)$ - [F,NC] 

您还应该将“热链接保护”指令(上面)移到路由指令之前 否则,在热链接保护能够阻止请求之前 ,可以(取决于URL格式)路由URL。

编辑您的虚拟主机:

1.登录您的服务器。

2. cd / etc / apache2 / sites-available /

3.您可以编辑默认web1或... virtual-host- .conf -file。 输入nano web1.conf (...)并编辑您的文件。

<VirtualHost *:80>
    ServerName yoururl.com      
    ServerAdmin webmaster@localhost
    DocumentRoot /var/www/web1/htdocs/
    <Directory /var/www/web1/htdocs/>
            Options Indexes FollowSymLinks MultiViews
            AllowOverride all
            Order allow,deny
            allow from all
    </Directory>
    ErrorLog /var/log/apache2/error.log
    LogLevel warn
    CustomLog /var/log/apache2/access.log combined
    ServerSignature On
</VirtualHost>

4.停止Apache2并重新启动它 - /etc/init.d/apache2 stop和/etc/init.d/apache2 start。

5..htaccess上传到根目录并进行测试。

如果您使用Cloudflare ,则SSL设置中的“ 始终使用HTTPS ”设置中有一个选项。 您还可以使用转发URL操作

http://yoururl.fqdn/*
redirected with a 301 response code to
https://www.yoururl.fqdn/$1

暂无
暂无

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

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