Articles of mod rewrite

LDAPvalidation代理根据LDAP组添加标头

我正在尝试设置一些WebSSO机制,允许我的客户对内部Active Directory进行身份validation,然后添加包含凭证信息的安全(https)头。 版本1确定:validation并添加标题 第一个版本“非常”简单。 我正在使用Apache和mod_auth_kerb来validation,然后添加标题。 以下configuration是现有的一个kinsnippet。 <VirtualHost *:80> ServerName external-sso.corp.fr RewriteEngine On </VirtualHost> <location /app2> # Authentication AuthType Kerberos AuthName "Active Directory Authentication" KrbMethodNegotiate On KrbMethodK5Passwd On KrbLocalUserMapping On KrbAuthRealms CORP.REALM.FR Krb5KeyTab /etc/krb5/http-myserver.corp.realm.fr.keytab Require valid-user # Identification AuthLDAPURL "ldaps://corp.realm.fr:636/DC=realm,DC=corp,DC=fr?sAMAccountName?sub?(objectClass=*)" AuthLDAPBindDN "CN=App2,OU=cloud,OU=prod,OU=Authentication,DC=realm,DC=corp,DC=fr" AuthLDAPBindPassword "*******" AuthLDAPGroupAttributeIsDN on Require valid-user # Adding Information into headers RewriteCond %{REMOTE_USER} (.+) […]

Apache2:尝试将子域映射到子目录

所以基本上我想有:sub.domain.com/ 什么 – > domain.com/asub / 什么 我对此有点新,有点困惑。 我做的第一件事就是configuration我的DNS设置,以便sub.domain.com使用CNAME访问domain.com(Alogging和IP会更好吗?) 接下来,我进入我的VirtualHost文件,并有: RewriteEngine on RewriteCond %{HTTP_HOST} www.(.+) [NC] RewriteRule ^/(.*) http://domain.com/$1 [R] RewriteCond %{HTTP_HOST} ^sub.domain.com RewriteRule ^/(.*) http://domain.com/asub/$1 [R] 所以第一个规则是为了处理www。 并确保被正确捕获,它的工作原理。 第二个规则是我为子域映射添加的东西,它似乎没有做任何事情

虚拟主机configuration和mod_rewrite – 删除PHP扩展和添加正向斜杠

在我的生产服务器上,事情没有问题:在我的.htaccess文件中,PHP扩展删除和尾部的斜杠规则已经就位。 但在当地,这是行不通的(好,部分,无论如何)。 我正在运行Apache2虚拟主机的网站。 在这种情况下,我决定不使用.htaccess文件,而只是将规则添加到httpd-vhosts.conf文件中,我听说如果可能在服务器上,这是更好的方法。 虚拟主机正在工作,我用于我的网站的URL是这样的: devserver:9090 这是我的httpd-vhosts.conf文件: NameVirtualHost *:9090 # for stuff other than this site <VirtualHost *:9090> ServerAdmin admin@localhost DocumentRoot "/opt/lampstack/apache2/htdocs" ServerName localhost </VirtualHost> # for site in question <VirtualHost *:9090> ServerAdmin admin@localhost DocumentRoot "/opt/lampstack/apache2/htdocs/devserver" ServerName devserver <Directory "/opt/lampstack/apache2/htdocs/devserver"> Options Indexes FollowSymLinks Includes AllowOverride None Order allow,deny Allow from all </Directory> <IfModule rewrite_module> RewriteEngine […]

如何在不设置ServerName的情况下redirect/重写FQDN URL?

通常在企业内部网中,用户不需要提供FQDN就可以将URL指向主机名。 例: http://internalHost 代替 http://internalHost.example.com 我想redirect用户/重写URL,以便一切都将使用FQDN。 这里是catch:我不想显式地设置ServerName。 (这是为了部署在多个Intranet上的产品,所以我们不能提前知道ServerName的值)。 根据: http : //wiki.apache.org/httpd/CouldNotDetermineServerName Apache使用反向查找来确定默认的FQDN。 我如何使用/引用Apache正在使用的mod_rewrite或redirect的FQDN?

如何使用mod_rewrite抽象获取子域名请求

我一整天都在这里,我认为自己掌握了正则expression式,但是我不再相信自己能做到。 我搜遍了,阅读了一些关于mod_rewrite的可怕指南,我很难过。 我想让这个电话 subdomain.domain.com/u/satbirkira 看上去和上面完全一样,但是执行并显示它 domain.com/user.php?user_name=satbirkira?subdomain_given=subdomain 这应该是非常简单的,但我不明白。 以下是我想到的: RewriteCond %{HTTP_HOST} ^(.*)user.php\?user_name=(.*)$ [NC] RewriteRule ^(.*)$ http://%1%{REQUEST_URI}/u/$3 我不知道为什么一些RewriteCond中断,如果你删除无用的捕获点像第一个(。*),但我已经学会了滚动它。 我将不胜感激,如果有人会解释为什么方法是不正确的,语法,捕获点和replace以及variables。 编辑 它类似于http://roshanbh.com.np/2008/03/url-rewriting-examples-htaccess.html#4上的目标,“4)将yoursite.com/user.php?username=xyz改写为yoursite .com / xyz“期望答案对我来说没有任何意义。

当源代码包含“?”时重写规则

抓我的头在这个。 我有一个旧的url: http://myserver/blog/archive?openview&type=Category&key=Demo 和一个新的URL http://myserver/blog/categories/Demo 我试图得到这个重写规则。 我认为这将是: ^/blog/archive\?openview&type=Category&key=(.*) /blog/categories/$1.html [NC,R=301,L] 但是这没有任何作用。 我尝试了URL和规则(用/replace?): http://myserver/blog/archive/openview&type=Category&key=Demo ^/blog/archive/openview&type=Category&key=(.*) /blog/categories/$1.html [NC,R=301,L] 而且这个按预期工作。 所以我有点笨拙如何处理? 用于匹配旧的url。 我发现的所有样本都描述了相反的情况。 发送“漂亮”的URL到丑陋的一个。 在我的情况下,“丑陋”的url是过去人们collections的url,我想确保他们正确地获得新的数据

重写一个目录到另一个目录没有redirect

我有以下重写规则: RewriteRule ^support/(.*)$ /blog/support/$1 [R=301,NC,L] 但是,它只是一个简单的redirect。 我想要的/support显示/blog/support的内容,而无需更改/blog/support的URL。 我怎样才能做到这一点? 另外,以上只适用于/support有尾随斜线。

尽pipe重写规则匹配,404返回

我有一个重写规则,将所有请求发送到index.php : RewriteRule ^.*$ index.php [NC,L] (除了RewriteEngine On ,这就是.htaccess文件中的所有内容) 它工作,除非请求path以index/开头,在这种情况下,结果是404 Not Found 。 如果我将index.php的文件名更改为index2.php (并重写规则以匹配它),它将再次开始工作,所以当请求的path的第一个段等于目标文件的第一个段时 , 显然会有冲突 。 mod_rewrite日志包含这个(当请求/index/hello , 失败 ): add path info postfix: /path/to/index.php -> /path/to/index.php/hello strip per-dir prefix: /path/to/index.php/hello -> index.php/hello applying pattern '^.*$' to uri 'index.php/hello' rewrite 'index.php/hello' -> 'index.php' add per-dir prefix: index.php -> /path/to/index.php initial URL equal rewritten […]

试图了解这组Apache2重写规则

我有以下的Apache2重写规则,我试图破译他们背后的意思: 1. RewriteEngine on 2. RewriteCond %{REMOTE_ADDR} !^1\.2\.3\.4 3. RewriteCond %{REQUEST_URI} !\.(css|gif|jpg|png)$ 4. RewriteCond %{DOCUMENT_ROOT}/../tmp/stop.txt -f 5. RewriteCond %{DOCUMENT_ROOT}/%{REQUEST_FILENAME} !-f 6. RewriteRule ^(.*)$ /$1 [R=503,L] 打开RewriteEngine 如果请求的地址不是来自IP 1.2.3.4 如果请求的URI不包含资源,则以.css或.gif或.jpg或.png结尾 如果URI请求../tmp/stop.txt(并且它是一个文件) 如果请求的path不是普通文件 如果规则2,3,4,5中的任何一个为真,则显示503状态页面? 我closures了吗? 谢谢

Apache2和rewritemap – 几个小时的尝试

我坚持与rewritemap问题。 我想要做的是将成千上万的几乎随机的url重新导向新的url。 我将手动build立地图,但我需要这个代码来工作。 RewriteCond %{HTTP_HOST}%{REQUEST_URI}\?%{QUERY_STRING} (^example\.com.abcd.cat_4)(.*) RewriteRule .* ${url_rewrite_map:$1|NOTFOUND}? [R=301,L] 我想地图看起来像这样: example.com/abcd/cat_4 http://example.com/345_exact_address_of_page 旧的url看起来像: http://example.com/abcd/cat_4=0?Xi4B7WoN;;54 我想让他们改写成: http://example.com/345_exact_address_of_page 我尝试了很多东西,但我无法做到这一点…你能帮我吗?