Articles of mod rewrite

使用Mod Rewrite / Regex解码URL查询string

我有以下编码的url https://example.com/external-image?url=http%3A%2F%2Fwww.thirdpartydomain.com%2FTWM%2FImages%2F1264%2F143242%2FFull%2F2201625016119496.jpg 我使用国防部重写parsing查询string,然后代理的url。 我这样做的原因是从其他第三方网站使用我自己的SSL安全的共享图像。 下面的代码包含非编码的查询参数,这些参数可以很好地工作。 示例url https://example.com/external-image?url=http://www.thirdpartydomain.com/TWM/Images/1264/143242/Full/2201625016119496.jpg 示例代码 RewriteCond %{QUERY_STRING} url=((?:https?:\/\/)?(?:[^@\n]+@)?(?:www\.)?([^:\/\n]+).*) [NC] RewriteRule ^.*/external-image$ %1 [P,NC,L,E=new_host:%2] <If "-T reqenv('new_host')"> RequestHeader set Host %{new_host}e </If> 我的目标是编码我的查询参数在浏览器中形成一个有效的url,然后解码查询参数之前,我代理的url。 任何人有任何想法来处理这个最好的方法?

如果cookie不存在,写条件不起作用

参考: 正确的方法来阻止一个网站,如果一个cookie不存在apache 2.4 我们遵循了答案,但没有奏效。 当cookie不存在(或包含正确信息)时,我们希望redirect到另一个页面。 我们试过这个: RewriteEngine on RewriteCond %{REMOTE_ADDR} !^123\.123\.123\.123 RewriteRule .* – [R=503,L] 以上作品为负面条件。 我们尝试了这些例子(我们必须改变url才能发布问题): RewriteCond %{HTTP_COOKIE} !abc_f8Dple7LxGXcSUgHjFrx RewriteRule .* www.example.co.uk/no-access [R=301,L] RewriteCond %{HTTP_COOKIE} !^abc_f8Dple7LxGXcSUgHjFrx=([^;]+) RewriteRule .* www.example.co.uk/no-access [R=301,L] RewriteCond %{HTTP_COOKIE} !^abc_f8Dple7LxGXcSUgHjFrx RewriteRule .* www.example.co.uk/no-access [R=301,L] RewriteCond %{HTTP_COOKIE} !abc_f8Dple7LxGXcSUgHjFrx=([^;]+) RewriteRule .* www.example.co.uk/no-access [R=301,L] 这些都没有工作。 如果我们删除! 符号(使其成为一个积极的条件),他们的工作。 有人可以帮忙吗? 我们希望得到这个在Apache 2.2和2.4上的工作,因为我们无法在两者上工作。

Apache的RewriteRule不能抑制扩展,其他的东西,工程

我在AWS上有一个EC2。 configuration服务器(Apache 2,PHP 7.0,…),启用mod_rewrite。 我之前做了很多次这个过程,但从来没有在Ubuntu 16.04上做过。 毕竟,testing我的服务器我观察到: RewriteRules可以工作,但是如果它改变了URL或扩展名则不行。 例: 这不工作: <IfModule mod_rewrite.c> SetEnv HTTP_MOD_REWRITE On AcceptPathInfo On RewriteEngine On RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule ^dieta/([\w-]+)?/?([\w-]+)?/?$ dieta.php?usuario_id=$1&dieta_id=$2 [L,QSA] RewriteRule ^diario/([\w-]+)?/?([\w-]+)?/?$ diario.php?usuario_id=$1&data_registro=$2 [L,QSA] RewriteRule ^diario-fisico/([\w-]+)?/?([\w-]+)?/?$ diario-fisico.php?usuario_id=$1&data=$2 [L,QSA] RewriteRule ^treino/([\w-]+)?/?([\w-]+)?/?$ treino.php?usuario_id=$1&treino_id=$2 [L,QSA] </IfModule> <IfModule mod_deflate.c> AddOutputFilterByType DEFLATE text/text text/html text/plain text/xml text/css application/x-javascri$ </IfModule> 在这个例子中: www.link.com/dieta/50/20 […]

Apache + MOD_JK:重写url+ ProxyPassing通过AJP

我有一个Apache 2.4.23 + OpenSSL 1.0.2j正面服务器。 然后我安装了Tomcat 7的另一台服务器。 这个想法是,Apache在*:443上有一个VHOST,它使用ProxyPass根据指定的URL通过AJP发送请求到Tomcat服务器。 这是我的vhosts.conf文件(它有SSLconfiguration,因为我不想使用httpd-ssl.conf文件,因为我必须改变很多东西),根据这个网站: https://mozilla.github.io/server-side-tls/ssl-config-generator/ ################################################################################################################## # VHOSTS HTTP # redirect all HTTP to HTTPS (optional) <VirtualHost *:80> ServerAlias * RewriteEngine On RewriteRule ^(.*)$ https://%{HTTP_HOST}$1 [redirect=301] </VirtualHost> ################################################################################################################## # VHOSTS HTTPS Listen 443 # modern configuration, tweak to your needs SSLProtocol all -SSLv3 -TLSv1 -TLSv1.1 SSLProxyProtocol all -SSLv3 -TLSv1 -TLSv1.1 […]

redirect,更改URL或redirectHTTP到HTTPS的Apache – 你想知道的所有关于Mod_Rewrite规则,但不敢问

这是关于Apache的mod_rewrite的典型问题 。 更改请求URL或将用户redirect到与原始请求不同的URL是使用mod_rewrite完成的。 这包括诸如: 将HTTP更改为HTTPS(或其他方式) 将请求更改为不存在的页面以replace新的replace。 修改URL格式(例如?id = 3433到/ id / 3433) 基于引用者基于浏览器呈现不同的页面,基于月球和太阳下的任何可能。 任何你想搞乱的URL 一切你想知道Mod_Rewrite规则,但不敢问! 我怎样才能成为写mod_rewrite规则的专家? mod_rewrite规则的基本格式和结构是什么? 我需要掌握哪些正则expression式的forms/风格? 编写重写规则时最常见的错误/陷阱是什么? 什么是testing和validationmod_rewrite规则的好方法? 是否有我应该知道的mod_rewrite规则的SEO或性能影响? 有没有常见的情况下,mod_rewrite似乎是正确的工具,但不是? 什么是一些常见的例子? 一个地方来testing你的规则 htaccesstesting仪网站是一个很好的地方玩你的规则和testing。 它甚至显示debugging输出,所以你可以看到什么匹配,什么没有。

如果uri的第一部分不是文件,则nginx mod_redirect

我正在从Apache迁移到Nginx服务器,并试图找出如何用nginxconfigurationreplace我的.htaccess 。 在我重写我想启用漂亮的链接,并需要服务器来检查,如果第一部分不是一个文件,然后redirect到index.php否则redirect到该文件。 例: 我有两个PHP文件在根目录: index.php和files.php 。 https://example.com/token/login —> index.php/token/login https://example.com/index.php/token/login —> index.php/token/login //same as above https://example.com/files.php/token/login —> files.php/token/login 我目前的/默认文件是 server { listen 80 default_server; listen [::]:80 default_server; server_name vpn.simpleinformatics.com www.vpn.simpleinformatics.com; return 301 https://$server_name$request_uri; } server { # SSL configuration listen 443 ssl http2 default_server; listen [::]:443 ssl http2 default_server; include snippets/ssl-vpn.simpleinformatics.com.conf; include snippets/ssl-params.conf; root […]

无法获取远程用户值

使用Apache Ldap身份validation来使用Tomcat。 我可以看到通过TCP DUMP,我的HTTP头发送remote_user:.. RICHARD到tomcat。 我已经尝试了mod_AJP和mod_HTTP 但不能通过我的Restful java spring webservices打印remote_user。 是的,在server.xml中Tomcatauthentication =“false”。 为什么我不能打印REMOTE_USER请帮助。

codeIgniter不能在主域到子文件夹之后工作

我从HostGator购买新的多域共享托pipe计划。 www.example.com是我的主域(根域) public_html/ example .htaccess 我在public_html / .htaccess中使用此代码更改我的主域名 RewriteEngine on RewriteCond %{HTTP_HOST} ^example.com$ [NC,OR] RewriteCond %{HTTP_HOST} ^www.example.com$ RewriteCond %{REQUEST_URI} !example/ RewriteRule (.*) /example/$1 [L] 现在public_html / example是我的新主域 我在示例文件夹中设置CodeIgniter项目,它为www.example.com/工作,但不工作www.example.com/index.php/about它是返回No input file specified. 这是我在public_html/example/.htaccess CodeIgniter public_html/example/.htaccess <IfModule mod_rewrite.c> RewriteEngine On RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule ^(.*)$ index.php/$1 [L] </IfModule>

尝试使用和不使用斜线redirect

我已经将博客移动到一个子域,并在子域所有的类别已经改变,所以我想做一个从旧域到子域(不同的托pipe)301redirect列表。 我遇到的问题是在尾部的斜杠上添加,所以我不必列出每个URL两次。 我在/blog/.htaccess试过这个: RewriteEngine On #RewriteRule ^(.*)$ http://domain.com/blog/$1/ [L,R=301] Redirect 301 /blog/test/ https://new.domain.com/test/ Redirect 301 /blog/example/ https://new.domain.com/example/ (etc…) 这不起作用,因为浏览器检测到太多的redirect。 这里的正确语法是什么? 我也试过: RedirectMatch /blog/test/?$ https://new.domain.com/test/ [L,R=301] 但是,这似乎并没有工作。

redirect到我的Laravel项目文件夹

我在.htaccess文件中有以下内容。 我希望它redirect到我的项目文件夹/hc是在.htaccess相同的水平。 redirect没有发生,它仍然显示index.html的内容。 RewriteEngine On RewriteBase /hc/ <Files .*> Order Deny,Allow Deny From All </Files> RewriteCond %{HTTP_HOST} ^example.com$ [NC] RewriteRule ^(.*)$ http://www.example.com/$1 [L,R=301] RewriteRule ^(?:application|modules|system)\b.* index.php/$0 [L] RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule .* index.php?/$0 [PT,L,QSA]