Articles of mod rewrite

除了使用.htaccess的一个path之外的每个URL强制使用SSL

我试图强制执行每个url除了第一个段/preview之外的SSL。 http://test.example.com/preview/blah/blah 应该被规则忽视; 每个其他的URL都应该被强制使用SSL。 我使用的是CentOS 6.4,Apache和CodeIgniter。 我的.htaccess文件: RewriteEngine On RewriteBase / RewriteCond %{HTTPS} !=on RewriteCond %{REQUEST_URI} !^/preview/ RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301] RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule ^(.*)$ index.php?/$1 [L] 通常,CI URL在被最后一条规则重写之前看起来像这样: http://test.example.com/index.php?/preview/blah/blah 我试过了: RewriteCond %{HTTPS} !=on RewriteCond %{REQUEST_URI} !^/index.php?/preview/ RewriteCond %{REQUEST_URI} !^/preview/ RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301] 那也行不通。 我究竟做错了什么?

.htaccess正在停止工作,而WP网站的工作,为什么?

我有三个站点在一个共享主机(Bluehost)中运行一个专用的IP地址。 说明如下: example.com =>这是主站点和域名,是一个WP example.net =>这是一个附加域名(不知道你是否熟悉这个术语),并正在运行另一个WP站点 subsite.example.net =>这是一个独立的PHP应用程序 每个WP都有它自己的.htacess文件,如下所示: # BEGIN WordPress <IfModule mod_rewrite.c> RewriteEngine On RewriteBase / RewriteRule ^index\.php$ – [L] RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule . /index.php [L] </IfModule> # END WordPress 有了这个.htaccess文件,两个WP网站都可以正常工作,但独立的应用程序却没有。 如果我删除.htaccess文件然后是相反的,独立的应用程序工作,但WP网站没有。 有没有可以帮助我find解决这个问题? 更新 我正在使用独立PHP应用程序的.htaccess文件的以下configuration: <IfModule mod_rewrite.c> RewriteEngine on RewriteBase / RewriteRule ^index\.php$ – [L] RewriteCond %{REQUEST_FILENAME} !-f RewriteCond […]

Apache – redirectsuddomain到主域

我重build了我的旧网站。 该旧网站有一个子域名: forum.example.com 。 现在,它不再存在了。 使用forum.example.com访问我的网站的人应该被redirect到example.com 。 我的.htaccess文件: RewriteEngine On RewriteBase / RewriteCond %{HTTP_HOST} !^example.com$ [NC] RewriteRule ^(.*)$ http://example.com/$1 [L,R=301] 如果主机不是example.com ,则redirect到example.com 。 不应该forum.example.com适合的条件? 现在对于问题的可选部分,如果有人能够向我解释上述规则,那就太好了。 以下是我在上述规则中理解的内容: 如果主机不是example.com ( !^example.com$ ) redirect到http://example.com 。 我不明白的是规则正则expression式的第一部分: ^(.*)$ ,然后是对它的引用( $1 )。 如何匹配所有可以作为请求的文件path? 难道它不会这样吗? http://example.com/http://www.example.com/[requested file]

无法弄清楚如何在Ubuntu上启用mod_rewrite

我觉得我已经做好了一切: josiah@BOX-OF-DOOOM:~$ sudo apache2ctl start apache2: Could not reliably determine the server's fully qualified domain name, using 127.0.1.1 for ServerName josiah@BOX-OF-DOOOM:~$ sudo a2enmod rewrite Module rewrite already enabled josiah@BOX-OF-DOOOM:~$ sudo apache2ctl restart apache2: Could not reliably determine the server's fully qualified domain name, using 127.0.1.1 for ServerName josiah@BOX-OF-DOOOM:~$ 然后在我的.htaccess(这是CodeIgniter): <IfModule mod_rewrite.c> RewriteEngine On RewriteBase / […]

还有一个mod_rewrite的问题

我试图让我的PHP项目之一运行mod_rewrite。 不幸的是,它不工作,我总是得到404错误。 我的url如下所示: http://admin.domain.com/index.php?page=#1&action=#2 我想重写这个到上面的URL: http://admin.domain.com/#1/#2/ 有一些特殊情况,如没有动作或附加参数被指定。 这是我的虚拟主机configuration( 编辑 ): <VirtualHost *:*> ServerName admin.domain.com ServerAdmin webmaster@localhost DocumentRoot /var/www/ <Directory "/var/www/"> Options Indexes FollowSymLinks MultiViews AllowOverride All Order allow,deny Allow from All </Directory> ScriptAlias /awstats/ /usr/lib/cgi-bin/ Alias /awstats-icon/ /usr/share/awstats/icon/ ScriptAlias /cgi-bin/ /usr/lib/cgi-bin/ <Directory "/usr/lib/cgi-bin"> AllowOverride None Options +ExecCGI -MultiViews +SymLinksIfOwnerMatch Order allow,deny Allow from all </Directory> […]

使用Apache将http://example.comredirect到http://example.com/mylink的简单方法是?

刚开始尝试了解所有的指令和选项如何在Apache下工作。 我希望对我的一个站点(只在服务器上运行一个站点)进行redirect,这样当http:/example.com发出请求时,服务器会自动将它们redirect到http://的子urlexample.com/mylink 。 我试图把redirect到位于/ etc / apache2 / sites-enabled的文件来重写这个,但是然后顶级域名的URL抱怨它没有正确的redirect。 我想我想要的是浏览器redirect,并认为使用 RewriteEngine On RewriteRule ^/$ /mylink [L,R] 将工作,但将其放入一个.htaccess文件不起作用(redirect,但立即给500内部服务器错误。) 把它放到启动了/ etc / apache2 / sites-enabled的文件中,在尝试重新启动Apache时会出现configuration错误。 我知道这是简单的…但是我错过了什么?

从root .htaccess重写规则中排除一个目录以允许它被密码保护?

上个星期我花了很多时间来解决这个问题,但不pipe我尝试了什么,我都无法把它工作。 我的网站主持人说,他们没有任何人对htaccess文件有足够的了解,以使其运行起来(鼓励,对吧?),而我从CMS购买CMS的公司也无法确定解决scheme。 我也在这里和其他网站上看过几十个答案,但是我根本无法解决我的问题。 这里的交易:我的CMS – Invision电源板 – 生成以下.htaccess文件,它位于网站的根目录: <IfModule mod_rewrite.c> Options -MultiViews RewriteEngine On RewriteBase / RewriteCond %{REQUEST_FILENAME} .*\.(jpeg|jpg|gif|png)$ RewriteCond %{REQUEST_FILENAME} !-f RewriteRule . /public/404.php [L] RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule . /index.php [L] </IfModule> 我有一个子目录sub_dir ,我需要在子目录中使用.htaccess文件进行密码保护。 我通过cPanel设置了密码保护,如果网站根目录下的.htaccess文件被禁用,它可以正常工作。 如果网站根目录下的.htaccess文件没有被禁用,那么当我浏览到sub_dir ,主页被显示。 起初,我认为显示的主页可能与404页面重写有关,但即使我删除了404页面的重写条件和规则,主页仍然显示。 sub_dir .htaccess文件中的sub_dir是: AuthUserFile "/home/[user]/public_html/.htpasswd" AuthType Basic AuthName "subdir" require valid-user 正如我之前提到的,密码保护在根目录中的.htaccess文件被禁用时起作用。 它也适用于当我删除底部重写条件和规则(index.php的行),但删除404页的重写条件和规则不影响任何东西。 […]

重写规则:追加URL的path

更新 感谢所有迄今为止的答复。 我想清楚地说明,在我的例子中user (例如user1)之后的数字并不重要。 用户可以是任何字母数字名称。 我想确保如果指定了一个目录,我们在它的末尾添加“/faces/main.jsf”。 例如 我们想要URL看起来像: example.com/user1/faces/main.jsf 该系统可以附加像(我们必须允许的) http://example.com/user1/faces/main.jsf;jsessionid=Z_DV-bY6MuQGlIvflPwgdKDk60cNzOkWXbC5G18ILrjR0jKoGWnd!-617980607 如果请求看起来像这样: example.com/user1 example.com/user1/ 我想要“/faces/main.jsf”被追加到它。 我的重写规则有什么问题? <VirtualHost *:80> ServerName example.com ProxyPass / http://1.example.com:8888/ ProxyPassReverse / http://1.example.com:8888/ RewriteEngine On # RewriteLog /tmp/rewrite.log RewriteCond %{HTTP_HOST} !^example.com$ RewriteRule !^/(.) http://example.com/$1 [L,R] RewriteCond %{REQUEST_URI} !^/(.+/)faces/main.jsf.* RewriteRule !^(.+)/faces/main.jsf.*$ $1/faces/main.jsf [L,R] </VirtualHost>

ProxyHTMLURLMap不能在apache2.4中工作

我在ubuntu 14.04上使用apache2.4。 而且我已经启用了mod_proxy_html.But我的url并没有被一个新的取代。 我在apache2.2中也是这样做的,而且工作完美。 这是我的虚拟主机文件。 <VirtualHost *:80> ServerAdmin [email protected] ServerName www.example.com ServerAlias example.com DocumentRoot /var/www/html/www.example.com LogLevel error CustomLog /var/log/apache2/www.example.com_access.log combined ErrorLog /var/log/apache2/www.example.com_error.log #Proxy and cookies settings ProxyPreserveHost On ProxyPassReverse / http://www.example.com/example/control/ ProxyPassReverse / https://www.example.com/example/control/ ProxyPassReverse / /example/control/ ProxyPassReverseCookiePath /example / <Proxy balancer://cluster> BalancerMember ajp://10.14.78.45:8009 route=node01 keepalive=On loadfactor=1 ping=10 ttl=600 ProxySet timeout=60 stickysession=JSESSIONID nofailover=On </Proxy> RewriteEngine […]

当同名文件存在时,apache mod_rewrite失败

完整的.htaccess文件 RewriteEngine on RewriteBase / RewriteRule ^([a-z0-9_\-]+)/([a-z0-9_\-]+)/(index\.php)?$ /main.php?type=$1&action=$2 [NC,QSA,L] 所以, www.server.com/users/new/ redirect到: www.server.com/main.php?type=users&action=new 该规则在我的testing机器上正常工作。 但是 , 在另一台机器上, 如果有一个以相同名称开头的文件 ,则会失败: / |- main.php | +–[users] |- new.inc.js 请求 www.server.com/users/list/ –> 200 OK (main.php returns results as expected) www.server.com/users/new/ –> 404 Not Found 如果我删除`new.inc.js',请求将按照预期redirect。 什么configuration标志导致这种行为? (我现在头撞墙了一段时间了) 更新 (我添加了完整的.htaccess文件内容) index.html和index.php是目录索引 (这对我来说也没有意义:()