我是mod_rewrite的新手。 我的问题:我有两个规则相互碰撞。 在我的文档根目录中,我曾经只有一个.htaccess将所有传入的请求redirect到一个fast-cgi脚本,如下所示: RewriteRule ^(.*)$ fcgi-bin/python-script.fcgi/$1 [QSA,L] 现在我有一个文件夹在我的文档根目录中的PHP脚本,我们称之为“specialdir”。 如何将请求从www.mydomain.com/specialredirect到php的specialfolder而其余的请求仍然发送到fcgi脚本? 我试过了 RewriteRule ^special$ specialfolder/$1 [QSA,L] 但是这个请求显然仍然是由我的“catch all” ^(.*)$指令处理的。 我应该包括某种情况吗? 它将如何看? 编辑 :我完整的.htaccess文件 AddHandler fastcgi-script .fcgi RewriteEngine On RewriteCond %{REQUEST_FILENAME} !-f AuthType Basic AuthName "login" AuthUserFile /var/www/v/htuser Require valid-user #php rewrite RewriteRule ^special/(.*) specialfolder/$1 [QSA,L] #trac rewrite RewriteRule ^trac(.*)$ fcgi-bin/trac-proj/$1 [QSA,L] #django rewrite RewriteRule ^(.*)$ fcgi-bin/django/$1 [QSA,L] […]
我想写一个redirect规则,将发送所有传入的请求针对给定的服务器别名。 以下是我的.conf文件的样子。 我遇到与foo.com相关的第一条规则问题。 重写带有别名foo.com的请求根本不会发生。 我甚至不知道如何debugging这个… NameVirtualHost xxx.xx.x.194 <VirtualHost xxx.xx.x.194> ServerName foo.com ServerAlias www.foo.com RewriteEngine on RewriteRule ^(.*)$ /cgi-bin/redirect.py?url=spencer [L,QSA,PT] SetEnv force-proxy-request-1.0 1 SetEnv proxy-nokeepalive 1 </VirtualHost> <VirtualHost xxx.xx.x.194> ServerName bar.com ServerAlias www.bar.com Include /etc/httpd/conf.d/zumodo.common ErrorLog logs/zumodo_errors_log CustomLog logs/zumodo_log combined SetEnv force-proxy-request-1.0 1 SetEnv proxy-nokeepalive 1 </VirtualHost>
我有以下重写规则设置: rewritecond %{http_host} ^domain.com [nc] rewriterule ^(.*)$ http://domain2.com/$1 [r=301,nc] 现在这工作redirectdomain.com/index.htm到domain2.com/index.htm但是它不会redirect任何文件夹,例如domain.com/folder/将不会redirect到domain2.com/folder/
#Hide Index IndexIgnore * #Define ErrorDoc ErrorDocument 404 http://www.domain.com #REDIRECTS Redirect 301 /page.php http://domain.com Redirect 301 /inc/page.php http://domain.com Options +FollowSymlinks RewriteEngine on #Redirect all pages in a folder to a single URL RewriteRule ^dir/(.*)$ http://domain.com/index.php [L,R=301] #Redirect String RewriteRule ^index.php?var1=value&var2=(.*)&var3=(.*)$ http://domain.com [L,R=301] #Rewrite www to domain RewriteCond %{HTTP_HOST} ^www\.domain\.com [NC] RewriteRule ^(.*)$ http://domain.com/$1 [R=301,NC] 我正在使用上面的htaccess文件301redirect页面已被删除从服务器到主页。 […]
我想排除mod_rewrite为一个特定的目录。 我希望文件夹“phd_application”不被重写,也就是当一个url指向的时候 www.myserver.com/phd_application 它去那个文件夹。 它在上传到Web服务器时工作,但不能在本地工作,我不明白为什么。 我有本地和远程相同的.htaccess文件。 我错过了什么? 我有以下.htaccess <IfModule mod_rewrite.c> RewriteEngine on RewriteRule ^(phd_application/) – [L] RewriteRule ^$ app/webroot/ [L] RewriteRule (.*) app/webroot/$1 [L] </IfModule> .htaccess所在目录的内容 -rwxr-xr-x 1 183 Dec 19 12:43 .htaccess drwxr-xr-x 13 18 Dec 13 15:44 app lrwxrwxrwx 1 15 Dec 13 14:48 cake -> ../CakePHP/cake -rwxr-xr-x 1 1850 Dec 13 15:14 […]
我正在尝试在OSX上设置apache2,并遇到问题。 我试图代理一个域到127.0.0.1:8081(这是启动和运行),但当尝试通过Apache加载,我得到一个“网页找不到”。 我也没有收到error_log来指示发生了什么,“apachectl configtest”返回OK。 这些指令在运行apache2的linux服务器上工作正常。 在启动apache之后,我在日志中看到的最后一条消息是:[notice] Apache / 2.2.20(Unix)mod_ssl / 2.2.20configuration了OpenSSL / 0.9.8r DAV / 2 – 恢复正常操作 任何帮助将是伟大的,我不是apache专家! /private/etc/apache2/extra/http-vhosts.conf TransferLog /var/log/apache2/transfer_log ProxyRequests Off NameVirtualHost *:443 # # THIS IS WORKING OK # EVERYTHING ON PORT 80 IS CHANGED TO HTTPS # <VirtualHost *:80> ProxyRequests Off ProxyPreserveHost On RewriteEngine On RewriteCond %{HTTPS} off RewriteRule (.*) […]
我当前的主机使用FastCGI来进行PHP设置,当mod_rewrite指令redirect到带有PATH_INFO部分的URL时,这显然会导致一些问题。 例如,使用以下内容时会出现问题: RewriteEngine on RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule ^(.*)$ index.php/$1 在使用上述操作时,导航到重写的URL会导致PHP中的“No input file specified”错误消息,这意味着PHP没有正确传递文件进行parsing。 我已经能够从networkingsearch学习,这个问题只出现在FastCGI下运行PHP时,但我没有find一个直接的答案是为什么 。 相反,networking显然充斥着一些盲目改变重写以使用查询string(例如,将index.php/$1部分改为index.php?/$1 – 注意? )而不真正理解底层问题的人。 我知道这个问题是重写过程的一部分,或者是重写过程的结果,并且这不是FastCGI安装无法处理PATH_INFO URL的问题,因为$_SERVER['PATH_INFO']当我直接导航到www.example.com/index.php/foobar而不经过重写过程时,variables被适当地填充。 有人可以解释什么是在重写和随后交付给PHP造成的失败?
最近,我遇到了一个问题,其中一些页面404通过他们的无止境的path访问。 查询string(如?1234或index.php被附加到path时,相同的页面工作。 例: http://pagesofinterest.net/code/plugins/code-complete/ – 失败 http://pagesofinterest.net/code/plugins/code-complete/?123 – 成功 http://pagesofinterest.net/code/plugins/code-complete/index.php – 成功 我不确定这是一个mod_rewrite还是一个caching问题。 这里是我的.htaccess文件的内容: # Use PHP5.3 Single php.ini as default AddHandler application/x-httpd-php53 .php #ExpiresDefault A0 Header set Cache-Control "no-store, no-cache, must-revalidate, max-age=0" Header set Pragma "no-cache" DirectoryIndex index.php index.html RewriteEngine on RewriteCond %{HTTP_HOST} ^www.pagesofinterest.net [NC] RewriteRule ^(.*)$ http://pagesofinterest.net/$1 [R=301,NC] # Error documents ErrorDocument 404 […]
这是我的.htaccess文件。 RewriteEngine on RewriteCond %{QUERY_STRING} ^(run=[a-z0-9A-z]{13})$ RewriteRule %{QUERY_STRING} \? [L] 我所做的就是为所有QUERY_STRING重写QUERY_STRING ,类似于run=4f13665700694 ,什么也不做。 URL示例: http://thinkingmonkey.me/runs/?run=4f13665700694 : http://thinkingmonkey.me/runs/?run=4f13665700694 。 所以,RewriteCond应该匹配。 但是,上述不起作用。 但是,模式似乎是正确的。 因为, preg_match和RewriteRule使用PCRE – Perl Compatible Regular Expressions 。 我尝试使用preg_match 。 $subject = "run=4f13665700694"; $pattern = "/^(run=[a-z0-9A-z]{13})$/"; echo preg_match($pattern, $subject); 除了上面的例子,还会输出: 1 即成功匹配。 我不懂为什么。 我在这里错过了什么?
可能重复: 基于源 IP的Apache虚拟主机 对于由IP标识的某个访问者,如何从不同的DocumentRoot服务器内容?