更新:大部分解决。 现在只有在您尝试访问http://www.example.com/any-real-file-without-an-extension/anything-afterwards-that-doesnt-end-in-a-slash的情况下http://www.example.com/any-real-file-without-an-extension/anything-afterwards-that-doesnt-end-in-a-slash 。 我猜服务器认为any-real-file-without-an-extension可能是一个目录…不知道如何解决这个问题。 PHP将“PATH_INFO”定义为URL的一部分: 包含任何客户端提供的path名信息,尾随实际的脚本文件名,但在查询string之前(如果可用)。 例如,如果当前脚本通过URL http://www.example.com/php/path_info.php/some/stuff?foo=bar ,那么$_SERVER['PATH_INFO']将包含/some/stuff 。 截至目前,我的网站将http://example.com/ contact_us.php/ANYTEXTCANGOHERE视为http://example.com/contact_us.php 在这种情况下, /ANYTEXTCANGOHERE是PATH_INFO。 我想这样做,这个path信息被删除到文件名,否则返回一个404。 有什么办法可以做到吗? 这里是我的.htaccess现在看起来像。 这很简单。 只是一个301redirect到www和最后的反斜杠,以及强制关联到文件没有扩展名和重写没有扩展。 我没有服务器root权限。 ErrorDocument 404 /404.php ErrorDocument 503 /503.php #Force www: RewriteEngine on RewriteCond %{HTTP_HOST} ^foodthing.org [NC] RewriteRule ^(.*)$ http://www.foodthing.org/$1 [L,R=301,NC] #get rid of trailing slashes RewriteCond %{HTTP_HOST} ^(www.)?foodthing\.org$ [NC] RewriteRule ^(.+)/$ http://%{HTTP_HOST}/$1 [R=301,L] #1)externally redirect "/file.php" to […]
我正在使用mod_rewritesearch引擎友好的url。 我有这个很好的作品: RewriteRule ^Pay ./pay.php [L] #Pay 但是如果访问者inputhttp://example.com/pay (注意小写),我也想要匹配。 我曾尝试使用NC但我得到一个500错误。 我已经尝试了2个单独的规则一个大写和一个小写,但再次500错误。 这可以使用正则expression式在一行上完成吗? 就像是: RewriteRule ^([Pp])ay ./pay.php [L] #Pay 如果是这样,什么是正确的方法? 如果不是我怎么能不使用mod_spelling来完成这个?
我有一个URL如下www.example.com/fr_FR curl返回types如下: HTTP/1.1 200 OK Date: Mon, 16 Oct 2017 10:35:19 GMT Server: Apache Set-Cookie: PHPSESSID=img4385scm6ldm6vngtntsrou1; path=/; HttpOnly Cache-Control: no-cache Set-Cookie: FirstVisit=1; expires=Wed, 18-Oct-2017 10:35:20 GMT; Max-Age=172800; path=/; httponly Cache-Control: no-cache Content-Type: text/html; charset=UTF-8 我的.htaccess包含以下指令: <IfModule mod_deflate.c> AddOutputFilterByType DEFLATE text/html text/plain text/xml text/css application/x-javascript application/javascript application/rss+xml application/xml application/xhtml+xml application/x-font-ttf application/x-font-opentype image/svg+xml </IfModule> 问题是,特定的URL没有被gzip,但是,如果我访问.html文件,或者如果我直接在我的apache虚拟主机添加AddOutputFilterByType DEFLATE text/html […]
我有一个configuration了mod_wsgi的Django站点,使用Apache 2.4作为Web服务器。 虚拟主机: <VirtualHost *:80> ServerName site.com ServerAlias site.com ServerAdmin [email protected] DocumentRoot /var/www/site <Directory /> Options FollowSymLinks AllowOverride None </Directory> Alias /media/ /var/www/site/media Alias /static/ /var/www/site/static <Directory /var/www/site> Require all granted AllowOverride All </Directory> WSGIScriptAlias / /var/www/site/nep/wsgi.py ErrorLog /var/log/apache2/site/error.log CustomLog /var/log/apache2/site/access.log combined # Possible values include: debug, info, notice, warn, error, crit, # alert, emerg. […]
我需要创build一些.htaccessconfiguration,我需要一些帮助。 我的Apache版本是2.4。 在Ubuntu上运行。 任务: 1)允许对经过authentication的用户和具有“白色”IP地址的用户使用test-uri-1; 2)仅允许经过authentication的用户访问test-uri-2和test-uri-3; 3)允许不受限制地访问所有其他URI; 4)只能在web项目的根目录下使用.htaccess文件。 我的第一个代码示例: SetEnvIf Request_URI ^test-uri-1$ require_auth=true SetEnvIf Request_URI ^test-uri-2$ require_auth=true SetEnvIf Request_URI ^test-uri-3$ require_auth=true SetEnvIf Request_URI ^test-uri-2$ require_auth_force=true SetEnvIf Request_URI ^test-uri-3$ require_auth_force=true AuthType Basic AuthName "Secure area" AuthUserFile /wwwroot/.htpasswd Order Deny,Allow Deny from all <If "-z reqenv('require_auth_force')"> Allow from 1.2.3.4 4.3.2.1 1.1.1.1 2.2.2.2 </If> Satisfy any Require valid-user […]
我找不到办法做到这一点。 这甚至有可能吗?
我们需要在正在进行大规模URL重组的网站上执行数百次301redirect。 这是做这个最好的方法是什么? 在.htaccess级别? 在代码级别?,apache级别? 如果.htaccess变得臃肿,会不会在网站上出现明显的减速? 谢谢
我正在Python中设置一个简单的testing页面。 我只有两个文件:.htaccess和index.py。 (两者的权限设置为755)当我尝试查看页面时,出现403 Forbidden错误 – 我该如何解决这个问题? 的.htaccess: RewriteEngine On AddHandler application/x-httpd-cgi .py DirectoryIndex index.py index.py: #!/usr/bin/python print "Content-type: text/html\n\n" print "test"
我试图阻止人们盗链到PDF和DOC文件。 通常,我会用这样的.htaccess规则来处理这个问题: RewriteEngine On RewriteBase / RewriteCond %{HTTP_REFERER} !^$ RewriteCond %{HTTP_REFERER} !^http://(www\.)?domain.com/.*$ [NC] RewriteRule \.(pdf|doc)$ /home/ [R=302,L] 然而,这些文件中的许多文件通过php脚本链接,例如filedownload.php?id = 5,然后触发PDF / DOC文件的下载。 有没有办法防止通过输出文件的MIME链接到这些文件? 其他方式? 编辑 – 添加此源来显示如何调用文件: header("Pragma: public"); header("Expires: 0"); header("Cache-Control: must-revalidate, post-check=0, pre-check=0"); header("Cache-Control: private",false); header("Content-Type: $ctype"); header("Content-Disposition: attachment; filename=\"".basename($fn)."\";" ); header("Content-Transfer-Encoding: binary"); header("Content-Length: ".$fs); echo $upload["file_contents"]; exit();
我已经安装了wiki.example.com(在远程Web服务器上,可供世界访问),以301.htaccessredirect到192.168.1.x / cgi-bin / foswiki / view(在内部服务器上,只能通过LAN)。 有没有办法,无论是在本地或远程,我可以掩盖本地IP? 所以用户会看到 wiki.example.com 在他们的地址栏中,而不是 192.168.1.x/cgi-bin/foswiki/view 两者都是运行Apache2的Linux服务器 在回答下面的问题:@ Zoredache – 我们没有一个内部的DNS服务器,所以fqdn不能得到可靠的解决。 我可能在设置中有错误。 你可以在networking上的Windows机器上使用netbios名称,但是linux机器不会在90%的时间内响应。 @ Dennis – 下面是我们的远程Web服务器上的当前.htaccess redirectMatch 301 ^(.*)$ http://192.168.1.x/foswiki redirectMatch permanent ^(.*)$ http://192.168.1.x/foswiki 也许我没有正确的做法。 设置内部DNS服务器目前不是一个选项。