Articles of mod rewrite

我怎样才能expression这个nginx的configuration为apache2重写规则?

if (!-e $request_filename){ rewrite /iOS/(.*jpg)$ /$1 last; rewrite /iOS/(.*jpeg)$ /$1 last; rewrite /iOS/(.*png)$ /$1 last; rewrite /iOS/(.*css)$ /$1 last; rewrite /iOS/(.*js)$ /$1 last; rewrite /Android/(.*jpg)$ /$1 last; rewrite /Android/(.*jpeg)$ /$1 last; rewrite /Android/(.*png)$ /$1 last; rewrite /Android/(.*css)$ /$1 last; rewrite /Android/(.*js)$ /$1 last; rewrite ^/(.*)$ /?route=$1 last; } 有一些虚空url,例如mysite.com/yourdetails,它们是由路由器类(它是一个以index.php作为入口点的PHP应用程序)在内部处理的,它们在nginx上似乎工作正常,但不是Apache: – / 我试过这个,但虚荣url不起作用 RewriteEngine On RewriteBase […]

当domain / foo是一个目录时,mod_rewrite漂亮的url

从简单的事情开始: RewriteRule ^(.*)$ index.php?page=$1 如果我也想要以下工作: RewriteRule ^/foo$ /index.php?page=foo #/foo IS a directory 这似乎只工作,如果R标志被设置,但然后完整的非漂亮的url被写入。 因此,似乎我可以REDIRECT现有的目录,但不能重写它们…也许与目录本身内的.htaccess? 或者在/foo/index.php中添加一些PHP魔法(如/index.php?page=foo)? 它会起作用吗? 它会被HTTP标准/search引擎优化? 请帮忙! PS:我想到了最奇怪的想法:redirect/ foo到/ not-a-dir,然后重写/ not-a-dir到/index.php?p=foo应该在理论上工作…但是…来吧真的?!?

为什么lighttpd或Apache2代理在访问index.html时更改我的URL?

我有一个尴尬的设置与Apache 2的networking服务器是守门人和代理stream量基于传入的域名: <VirtualHost *:80> ServerName example.org RewriteEngine On RewriteRule ^/(.*) http://localhost:3000/$1 [P] </VirtualHost> 在localhost:3000下运行我有一个lighttpd运行,它提供静态内容,并作为其他两个服务的反向代理,在端口3001和3002上运行。configuration如下所示: # lighttpd will also be used to forward requests to node.js server.modules = ( "mod_proxy" ) # This config is meant to work relative to certain directories, # it is not meant to be used somewhere globally in /etc/ var.projectRoot = […]

试图让Apache的mod_stats'/服务器状态'工作

mod_status是一个apache模块,可以让你看到apache的状态。 打开后,可以访问server.com/server-status,但是由于.htaccess文件中的mod_rewrite,我无法访问它。 下面是.htaccess文件。 <IfModule mod_rewrite.c> RewriteEngine On RewriteCond %{HTTP_HOST} othersite.com$ [NC] RewriteRule ^(.*)$ http://server.com/$1 [R=301] RewriteBase / RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule . /index.php [L] </IfModule> 当我停用上面, http://server.com/server-status工程。 这可能是mod_rewrite常见的问题,但我不知道如何解决它。

Mod重写cgi-bin

所以我想重写下面的url结构 mysite.com/cgi-bin/shop/shop.cgi/ 至 mysite.com/+ 我有这个作为一个规则,它的工作原理,但它不强制url打印在浏览器中,当你仍然指向旧的url。 所以我有重复的内容。 我已经尝试添加[R = 302],它不起作用。 [R = 302]使它打印出原来的旧url结构(/cgi-bin/shop/shop.cgi/%)。 有任何想法吗? RewriteRule ^\+([^*]+)/?$ /cgi-bin/shop/shop.cgi/$1 任何帮助将不胜感激!

Git智能HTTP(S)与URLredirect,无法正常工作

我正在GitList (Git的PHP web浏览器)和GIT智能HTTP(S)在同一域git.domain.ext下。 以下是实际设置: GIT智能HTTPurl格式为git.domain.ext / git / reponame.git GitList通过git.domain.ext / gitlist来提供 到现在为止还挺好。 一切正常。 我想达到的是以下几点: 任何forms的git.domain.ext / *。git的请求应该改为git.domain.ext / git / *。git 任何其他请求应该默认为git.domain.ext / gitlist 以下是我的Apacheconfiguration: <VirtualHost *:443> ServerName git.domain.ext DocumentRoot /home/user/www/git.domain.ext SetEnv REMOTE_USER=$REDIRECT_REMOTE_USER SetEnv GIT_PROJECT_ROOT /home/user/git/ SetEnv GIT_HTTP_EXPORT_ALL ScriptAlias /git/ /usr/lib/git-core/git-http-backend/ <Location /> AuthName "Git Authentication" AuthType Basic Require valid-user AuthUserFile /home/user/git/.htpasswd </Location> <LocationMatch […]

用于重组目录结构的Mod_Rewrite规则(或替代方法)

我工作的网站有这两页: http://www.africananimals.com/stripes/zebras 和 http://www.africananimals.com/news/zebras (这些不是真正的域名,只是例子。) 目录结构最近被重新组织,并且相同页面的URL改为: http://www.africananimals.com/zebras/stripes 和 http://www.africananimals.com/zebras/news 我想要一个mod_rewrite规则(或者更less资源的替代方法,比如Redirect命令或类似的东西)来使那些同时拥有旧url的页面的爱好者受益。 我需要这个工作http // www.africananimals.com和http // africananimals.com /版本的URL。 我的解决scheme是这样的: Redirect /stripes/zebras http://www.africananimals.com/zebras/stripes Redirect /news/zebras http://www.africananimals.com/zebras/news – 但我不确定我是否正确 在正则expression式上很糟糕,对.htaccess只有肤浅的理解,我一定会感激一些指导。

如何在同一台服务器上使用Apache和dynamic内容与Morbo一起提供静态文件?

我有端口80上的Apache httpd和端口3000上的Morbo httpd服务器服务perl Mojolicious代码。 Morbo只能从本地主机上获得。 现在我想要使用代理来设置虚拟主机,这样静态文件将由Apache提供,dynamic内容将由Morbo提供服务。 这是我的虚拟主机configuration: <VirtualHost *:80> ServerName mojo.myhost.com DocumentRoot /opt/mojo/public RewriteEngine on RewriteCond %{DOCUMENT_ROOT}%{REQUEST_FILENAME} !-f RewriteCond %{DOCUMENT_ROOT}%{REQUEST_FILENAME} !-d RewriteRule ^(.*) http://localhost:3000$1 [NS,P,L] ProxyPassReverse / http://mojo.myhost.com </VirtualHost> 问题是,当我尝试访问http://mojo.myhost.com/ Apache的subrequ由Apache发出,请求发送到Morbo是http://localhost:3000/error/noindex.html而不是http://localhost:3000/ 。 这里是mod-rewrite log的一部分: [rid#2b20905c58e0/initial] (2) init rewrite engine with requested uri / [rid#2b20905c58e0/initial] (3) applying pattern '^(.*)' to uri '/' [rid#2b20905c58e0/initial] (4) RewriteCond: input='/opt/mojo/public/' […]

mod_rewrite:将现有文件重写为slu,,slu to现有文件

我的情况如下:我有我的本地服务器上的public/文件夹中的静态文件。 任何进来的请求应该被转发到该文件夹​​,但是如果该文件夹中的文件被直接访问,它应该是404或redirect到'slug'。 例: Request: /my-file Should rewrite to: /public/my-file.html URL should be: http://localhost/my-file Request: /public/my-file.html Should rewrite to: /public/my-file.html URL should be: http://localhost/my-file 我在.htaccess有以下规则和条件: RewriteCond %{DOCUMENT_ROOT}/public/%{REQUEST_URI}.html -f RewriteRule ^.*$ /public/$0.html [L,C] RewriteCond %{REQUEST_URI} ^/public RewriteRule ^public/(.+).html$ /$1 [R=301,L] 从上到下: /public/{request}.html文件是? 如果(1)为真,则重写:/ /public/{request}.html ,并链接到(3)以防止redirect循环 原始请求是以/public开头的吗? 如果(3)为真,并且原始请求匹配public/{request}.html : /{request} ,则重写。 另外制作一个301头,告诉我的浏览器和抓取工具页面已经永久移动了。 请求将再次贯穿所有规则 所以,如果我们做了这两个要求: 1. Request: /my-file /public/my-file.html计算结果为true; […]

使用.htaccess更改端口和主机

我试图使用mod_rewrite基本上端口转发到另一个IP上的另一个端口的子域上的端口。 喜欢这个: sub.website.com:2000 –> 123.45.67.891:3000 这怎么可以使用mod_rewrite使用.htaccess文件? 我尝试了以下,但无济于事: RewriteCond %{HTTP_HOST} ^sub.website.com$ [NC] RewriteCond %{SERVER_PORT} ^2000$ RewriteRule ^(.*)$ https://123.45.67.891:3000/$1 [L,R=302]