Articles of mod rewrite

使用Apache2从同一个URL向web根外的多个目录提供服务

是否可以设置Apache来从同一个URL提供多个目录? 例如,假设我有两个位置的映像:/ mnt / imagestore1,/ mnt / imagestore2。 我想mysite.com/images/file.jpg显示从任一目录的图像。 它似乎不像以下这样的别名: Alias /images /mnt/imagestore1 Alias /images /mnt/imagestore2 而在文档根目录下使用mod_rewrite和.htaccess也没有起作用,尽pipe我对mod_rewrite的理解可能不在这里: RewriteCond /mnt/imagestore1/%{REQUEST_URI} -f RewriteRule ^(.+) /mnt/imagestore1/$1 [L] RewriteCond /mnt/imagestore2/%{REQUEST_URI} -f RewriteRule ^(.+) /mnt/imagestore2/$1 [L]

将所有http和https域名stream量重写为基于https的url的问题

我正试图获得所有的变化 http://www.example.com http://example.com https://www.example.com https://example.com www.example.com example.com 全部redirect到 https://www.example.com 我有以下mod_rewrite块: RewriteEngine on ReWriteCond %{SERVER_PORT} !^443$ RewriteCond %{HTTP_HOST} ^([az.]+)?example.com$ [NC] RewriteCond %{HTTP_HOST} example.com$ [NC] RewriteRule .? https://www.example.com%{REQUEST_URI} [R=301,L] 似乎除了一个: https://example.com不会被redirect到 按预期https://www.example.com 如果我删除了条件: ReWriteCond %{SERVER_PORT} !^443$ 所以它影响http和https,它仍然不像预期的那样。 我哪里错了? 谢谢

需要htaccess重写条件的http_host的名称

我想写一个规则,我不知道确切的http_host。 例如,我有(www.)?example.com 。 现在我需要构build以下example : (www.)?example.com/example/…在一个RewriteRule中。 那么我怎样才能把http_host分成名字呢?

mod_rewrite问题在Nginx后面的Apache

我有nginx代理到Apache作为后端为了nginx处理静态资产。 不幸的是,当我试图访问一个“漂亮的url”,它只是显示索引页面。 nginxconfiguration server { listen 80; root /var/www/example.com; index index.php index.html index.htm; server_name example.com www.example.com a.example.com b.example.com c.example.com; location / { try_files $uri $uri/ /index.php; } location ~ \.php$ { proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $remote_addr; proxy_set_header Host $host; proxy_pass http://127.0.0.1:8080; } location ~ /\.ht { deny all; } } Apache vhostconfiguration <VirtualHost 127.0.0.1:8080> […]

Apache将一些urlredirect到主页

我试图实现一个简单的重写,但看起来像我做错了什么。 我想要做的是,我有一个urlblog.example.com/articles/这给了我404,和其他url是blog.example.com/articles/abc,blog.example.com/articles/xyz等,这工作得很好,所以我想blog.example.com/articles/向我展示的主页是blog.example.com而不是404,但我不想要任何其他的url,其中有像/ articles / *受该规则的影响。 这是我迄今为止所尝试过的 RewriteRule ^/articles$ /index.php [R=302] 这不起作用 我也尝试了redirect Redirect "/articles" "http://blog.example.com/" 我工作,但它会更改浏览器中的url,也会影响以/ articles开头的所有其他url 任何帮助表示赞赏

在gitlab地址中删除双斜杠

我在我的个人服务器上设置了gitlab,并使用了这个答案和这个答案 (还有一些input来使它与我的apache安装一起工作。一切工作正常,当我去gitlab.example.com,我看到gitlab UI ,可以创build帐户等,但是当我检查了我转发的URI时,就是这样 https://gitlab.example.com//users/sign_in (注意域名后面的两个斜杠)。 这不是一个真正的问题,但我想知道这是为什么,我怎样才能解决这个问题 – 特别是因为当我从地址中删除一个斜线时,它工作的很好。 (所以https://gitlab.example.com/users/sign_in是完全一样的)。 事实上,我得到了两次转发: GET https://gitlab.example.com => 301 Moved Permanently Location:https://gitlab.example.com/ GET https://gitlab.example.com/ => 302 Found Location:https://gitlab.example.com//users/sign_in 这是我的apacheconfiguration文件(`/etc/apache2/sites-enabled/gitlab.conf): <IfModule mod_ssl.c> <VirtualHost *:443> ServerName gitlab.example.com ServerSignature Off ProxyPreserveHost On ProxyPassMatch ^(/[^/]+\.(html|png|ico|css|txt))$ ! ProxyPass /assets ! <Location /> Order deny,allow Allow from all ProxyPassReverse http://127.0.0.1:8080 ProxyPassReverse http://gitlab.example.com </Location> RewriteEngine on […]

如何使用/不使用https将两个域redirect到一个https站点?

我想要做以下事情:使用Apache,redirect所有以下url: http://example.com http://www.example.com http://beta.example.com https://example.com https://www.example.com https://beta.example.com 到相同的地方: https : //beta.example.com 。 我很接近,但不是那里。 这是我得到的: NameVirtualHost xxx.xxx.xxx.xxx:80 NameVirtualHost xxx.xxx.xxx.xxx:443 ### rewrite scheme via http://stackoverflow.com/questions/1100343/apache-redirect-from-non-www-to-www <VirtualHost xxx.xxx.xxx.xxx:80> ServerName example.com ServerAlias www.example.com DocumentRoot /var/www/html/example CustomLog /var/log/httpd/example-log combined ErrorLog /var/log/httpd/example-log </VirtualHost> <Directory /var/www/html/example> RewriteEngine on RewriteCond %{HTTP_HOST} !^www\. [NC] RewriteRule ^(.*)$ https://beta.%{HTTP_HOST}%{REQUEST_URI} [R=301,L] Options -Indexes Options +FollowSymLinks DirectoryIndex index.php […]

当访问所有其他文件被拒绝时,如何dynamic地将所有HTTP错误代码发送到一个PHP文件?

我有以下情况,我正在开发一个API。 我将所有stream量重写为一个名为: route.php PHP脚本,使用mod_rewrite : 1: RewriteEngine On 2: RewriteCond %{REQUEST_FILENAME} -f [OR] 3: RewriteCond %{REQUEST_FILENAME} -d 4: RewriteRule ^.* route.php [L] 其他文件不应该是可访问的,这就是为什么我只使用白名单来访问route.php 。 为此我使用这个: order allow,deny <FilesMatch "route\.php"> allow from all </FilesMatch> 我想发送所有的1xx,2xx(200除外),4xx,如果可能的话5xx HTTP状态码给PHP脚本(假设error.php?code=404 ,显示该状态码的dynamic错误页面。我可能error.php不允许在FilesMatch部分中访问error.php 。 我在本文中描述了部分我想要的东西,但我无法实现或设法按照上述方式使其工作。 我的目的是为了显示一个JSON输出(dynamic地基于状态码),如{'statusCode':'404','status':'Not Found'}包括我使用的所有常见(安全)HTTP头。

redirect选项在.htaccess文件中删除后redirect

我使用重写规则在我的apache服务器上做了一些redirect的事情,它运行良好,在我删除了这个选项之后,我的浏览器得到了redirect链接,但是当我在其他系统中testing它时,它并没有。 这对我来说很奇怪,我不知道是什么问题。 有没有逻辑解释这个或我梦想? 我在客户端使用win 10,在服务器上使用apache-2.2,如果他们帮助。 坦克。

删除在Apache目录中的尾部斜杠

我有以下urlwww.example.com/advice/现在注意在URL的末尾的斜线? 我希望将其移除为www.example.com/advice 。 现在,当我在浏览器中input该URL时,我将redirect到带有斜线的尾部,即使以curl为例。 现在我知道后面的斜杠正在增加,因为通知是一个实际的目录。 [steve@dev dev.www.example.com]$ curl -I https://dev.www.example.com/advice -k HTTP/1.1 301 Moved Permanently Date: Fri, 25 Nov 2016 08:20:11 GMT Server: Apache/2.4.6 (CentOS) Location: https://dev.www.example.com/advice/ Cache-Control: max-age=0 Expires: Fri, 25 Nov 2016 08:20:11 GMT Connection: close Content-Type: text/html; charset=iso-8859-1 [steve@dev dev.www.example.com]$ curl -I https://dev.www.example.com/advice/ -k HTTP/1.1 200 OK Date: Fri, 25 Nov 2016 […]