Articles of mod rewrite

最佳的mod_rewrite正则expression式。 匹配模式排列在正则expression式中的方式是不是?

我有以下几点: RewriteRule ([a-zA-Z0-9]{5})?/load_page/([0-9]+) 正则expression式的哪个configuration是最优的: RewriteRule ^/([a-zA-Z0-9]{5})?/load_page/([0-9]+) 要么 RewriteRule ^/load_page/([a-zA-Z0-9]{5})?/([0-9]+) 要么 RewriteRule ^/([a-zA-Z0-9]{5})?/([0-9]+)/load_page 谢谢

MOD环境中的Apache环境variables重写

在我的httpd.conf中我设置了一个variables SetEnv MY_URL_WWW "http://myURLtowhatever.com" 而在我的.htaccess中,我有一个重写规则,我要redirect到我的ENVurl RewriteRule ^redirect$ %{ENV:MY_URL_WWW} [L,NC,R=301,QSA] 这是行不通的,我真的很想,我做错了什么?

Apache2 – 同一个域的多个VirtualHosts

我有一个Apache服务器,我在本地主机上运行。 根http://localhost应该去一个VirtualHost应用程序(Joomla!),而我想要http://localhost/test去第二个VirtualHost – 一个简单的index.htmltesting文件。 我相信我想为此用户mod_rewrite,所以我已经安装。 我有以下两个VirtualHosts定义(我使用Ubuntu 11.04): 根 <VirtualHost localhost> ServerAdmin webmaster@localhost ServerName localhost DocumentRoot /srv/joomla </VirtualHost> testing <VirtualHost localhost> ServerName localhost DocumentRoot /srv/test ServerPath /test/ RewriteEngine On RewriteRule ^(/test/.*) /srv$1 </VirtualHost> 但是,当我去http://localhost/test/index.html甚至http://localhost/test我得到一个404 。 我究竟做错了什么? 谢谢!

Apache2:重写规则行为奇怪

我有我的.htaccess文件中的以下内容: <Directory /home/eamorr/sites/example.com/www> Options Indexes FollowSymLinks MultiViews Options -Indexes AllowOverride all Order allow,deny allow from all RewriteEngine on RewriteRule ^([^/.]+)/?$ index.php?uname=$1 [R,L] </Directory> 当我访问http://example.com/Eamorr时 , http://example.com/home/eamorr/sites/example.com/www/index.php?uname=Eamorr出现在地址栏中! 但我希望http://example.com/index.php?uname=Eamorr出现在地址栏中! (我需要在index.php中parsingjavascript中的URL)

.HTACCESS 2个域的重写规则

我有两个域,其内容在同一个文件目录中: http://www.alpha.com/ DIR: /var/www/alpha.com/ 和 http://www.beta.com/ DIR: /var/www/beta.com/ 我想要做以下事情: 当用户去 http://www.alpha.com/beta/ 他应该看到的内容 http://www.beta.com 并通过去例如 http://www.alpha.com/beta/index.php?a=3&b=2 他应该看到的内容 http://www.beta.com/index.php?a=3&b=2 等等。 我如何使用htaccesspipe理? 我应该在哪个目录中放置? 我想过: RewriteEngine On RewriteRule ^\.htaccess$ – [F] RewriteCond %{REQUEST_URI} ^/beta/(var1)$ RewriteRule ^.*$ http://beta.com/%1 但它不起作用。 而我在正则expression式方面不太好。 谢谢你的每一个答案!

nginx重写为按字母顺序的子目录

我试图将下面的Apache mod_rewrite规则转换成适当的nginx格式: RewriteCond %{REQUEST_FILENAME} (.*)/([^\/])([^\/]+)/?$ RewriteCond %1/%2/%2%3 -d RewriteRule ^/?.* /%2/%2%3 [L] 在实践中,这个规则重写裸目录请求,将它们放在基于第一个字符(区分大小写)的父目录中,所以http://example.com/foobar变成http://example.com/f/foobar ,等等。 其他的一切都是静态的内容,或者PHP,并通过FastCGI传递,并有location处理程序。

将子域虚拟主机子域redirect到path

我用Apache的虚拟主机为greptweet.com的一大堆子域名,其中每个twitter用户名是一个子域名,如<username> .greptweet.com。 问题是…子域名不能有下划线! 🙂 现在我重新构build了网站,我想永久性地将所有到子域的用户redirect到path: <username> .greptweet.com添加到path结构greptweet.com/u/ <username> 例如http://kaihendry.greptweet.com/到http://greptweet.com/u/kaihendry/ 理想情况下,我希望在Apache的httpd.conf <VirtualHost>节中实现这个function,而不是写入/ srv / www /

重写规则和代理

两台服务器。 example.net和example.com 在http://example.net上 ,我的httpd.conf包含 # example.net RewriteEngine On RewriteRule ^/felipetest2 http://example.com/webpage [P] 我得到一个302 Moved,这是指向http://example.net/webpage ,但应该是http://example.com/webpage 这是怎么回事? 在这些例子中,我可以控制.net和.com服务器。 我知道我可以用ProxyPass和ProxyPassReverse来做同样的事情,但是我正在试着去解决这个问题。 编辑:主要问题:如何显示维护页面,而不更改浏览器中的URL? 在同一个域上,或跨不同的域?

mod_rewrite全部80个stream量到443例外

我有一个运行在443和80上的虚拟主机。在80虚拟主机上,我有一个这样的规则。 Redirect permanent / https://localhost 我正在testing/ autos静态页面,我希望这个stream量不使用redirect规则,我希望这个页面从80虚拟主机提供没有SSL。 所以我试图设置一个RewriteCond然后一个RewriteRule的cond。 RewriteCond %https://localhost !/autos$ RewriteRule !^/var/www/autos – [C] 这不工作,因为我可能做错了。 有小费吗?

redirect在url中使用cgi-bin的页面

我在redirectpath中包含cgi-bin的url时遇到问题 例: http://website.com/cgi-bin/pc.storefront/en/product/product.aspx?iid=123 .htaccess redirect 301 /cgi-bin/pc.storefront/en/product/product.aspx?iid=123 http://website.com/homepage.html 使用该redirect服务器返回:此服务器错误消息传递上不存在/cgi-bin/pc.storefront/en/product/product.aspx。 但是,如果保持一切,并从等式中删除cgi-bin,那么redirect就可以完美工作。 服务器是使用mod_rewrite的apache2。 cgi也在httpd.conf中被禁用。 有没有关于redirectcgi-bin的问题?