Articles of mod rewrite

用mod_rewrite重写基本URL

我的域example.com指向public_html目录。 在目录public_html / php是我的index.php文件。 现在我希望URL example.com指向public_html / php / index.php 。 我必须用mod_rewrite来做这件事,因为我没有访问httpd.conf来做别名或者DocumentBase。 在目录public_html是我的.htacces文件具有以下内容: RewriteEngine on RewriteCond %{HTTP_HOST} exaple.com$ RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule ^(.*)$ /php/index.php [L,QSA] 这样做的一半,因为当我在我的浏览器中input像example.com/s的东西,它指向public_html / php / index.php,因为我希望它做。 但是,当我刚刚进入example.com它指向public_html 。 我能做些什么来解决这个问题?

RewriteMap语法正则expression式

在我的.htaccess我有吨的指令,相同的语法: RewriteRule ^(.*)/PRODUCT_1.aspx http://www.site.com/product.php?id_product=2891 RewriteRule ^(.*)/PRODUCT_2.aspx http://www.site.com/product.php?id_product=2896 一切正常。 现在,我在我的创build了一个RewriteMap,因为我需要增加速度(20.000redirect301在htaccess不好),所以: RewriteEngine On RewriteMap redirects dbm=db:/var/www/html/presta152/prestashop/redirects.db RewriteCond ${redirects:$1} !="" RewriteRule ^(.*)$ ${redirects:$1} [redirect=permanent,last] 而我的redirects.db由redirects.txt创build,其中包含: /PRODUCT_1.aspx http://www.site.com/product.php?id_product=2891 /PRODUCT_2.aspx http://www.site.com/product.php?id_product=2896 这工作,如果我尝试打电话为例:www.site.com/PRODUCT_1.aspx我redirect…但如果我尝试打电话www.site.com/everythingpossibileinside/PRODUCT_1.aspxredirect不起作用。 所以,在我的.htaccess这个规则: RewriteRule ^(.*)/PRODUCT_1.aspx http://www.site.com/product.php?id_product=2891 工程,但在我的RewriteMap号。 我想我必须改变这个指示: RewriteRule ^(.*)$ ${redirects:$1} [redirect=permanent,last] 我尝试了,但没有成功。 谢谢大家。

将不存在的子域redirect到基本域url

我使用的是我的域名为“example.com”的Droplr,前缀为“u”。 (u.example.com)。 前置不是一个子域,并通过Aloggingredirect到Droplr服务器的IP地址。 编辑— 换句话说,我没有创buildu.example.com作为example.com的子域名,而是创build了一个Alogging,使其像子域一样。 不过,我将urux.com中使用的域名更改为example.com,我试图用.htaccess设置一个redirect来将任何请求转发到u.example.com/abcd到example.com/abcd 。 我目前有以下,但似乎没有任何影响的领域。 请你能告诉我哪里出错了吗? RewriteEngine on RewriteCond %{HTTP_HOST} ^u.example.com$ [OR] RewriteCond %{HTTP_HOST} ^www.u.example.com$ RewriteRule ^(.*)$ http://example.com/$1 [R=301,L]

我正在使用Apache mod rewrie将httpredirect到https,但现在无法连接到localhost / phpmyadmin

这里是我的/ etc / apache2 / sites-enabled / 000-default <VirtualHost *:80> ServerAdmin [email protected] RewriteEngine On RewriteCond %{HTTPS} off RewriteRule (.*) https://mysite.com DocumentRoot /var/www/http <Directory /> Options None AllowOverride None </Directory> <Directory /var/www/http> Options -Indexes -FollowSymLinks MultiViews AllowOverride None Order allow,deny allow from all </Directory> ScriptAlias /cgi-bin/ /usr/lib/cgi-bin/ <Directory "/usr/lib/cgi-bin"> AllowOverride None Options +ExecCGI -MultiViews +SymLinksIfOwnerMatch Order […]

是否有一个排除子域部分的.htaccess域variables?

是否有一个.htaccessvariables我可以使用排除子域? 例如,如果域名是www.example.com ,那么我如何在我的.htaccess文件中使用example.com ? 我需要使用一个variables。 我不能硬编码example.com 。

将所有页面除外的所有页面都redirect到HTTP

我使用下面的重写规则将2个php页面redirect到https(以保护用户数据),但是每当我点击这些php页面上的任何链接时,它们都会使用https进行redirect,页面无法正确显示。 底部的规则是为了将任何其他页面redirect回http,但它们不起作用。 任何意见将不胜感激! RewriteEngine on RewriteCond %{HTTPS} off RewriteCond %{REQUEST_URI} ^/securepage1.php$ [NC] RewriteRule ^(.*)$ https://www.example.com$1 [L,R=301] RewriteCond %{HTTPS} off RewriteCond %{REQUEST_URI} ^/securepage2.php$ [NC] RewriteRule ^(.*)$ https://www.example.com$1 [L,R=301] RewriteCond %{HTTPS} on RewriteCond %{REQUEST_URI} !^/securepage1.php$ [NC] RewriteCond %{REQUEST_URI} !^/securepage2.php$ [NC] RewriteRule ^(.*)$ http://www.example.com$1 [L,R=301]

Apache达到内部redirect限制

我有以下问题: Request exceeded the limit of 10 internal redirects due to probable configuration error. Use 'LimitInternalRecursion' to increase the limit if necessary. Use 'LogLevel debug' to get a backtrace. Apache试图到达不存在的文件。 这是我的.htaccess: RewriteEngine on Options +FollowSymlinks RewriteCond %{HTTP_HOST} ^(www.)?domain.com$ RewriteCond %{REQUEST_URI} !^/subfolder/$ RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule ^(.*)$ /subfolder/$1 RewriteRule ^\??$ index.php [L] 我打开了日志,在日志里有这样的: […]

使用mod_rewrite的相当URL的冲突

我有2页的会员个人资料页面和公司简介页面,成员的url应该是: site.com/users/USER_ID公司的url应该是: site.com/COMPANY_ID 我在.htaccess有这个: #Members Profile Page RewriteRule ^users/(.*)$ modules/members/members_profile.php?id=$1 RewriteRule ^users/(.*)/$ modules/members/members_profile.php?id=$1 #Companies Profile Page RewriteRule ^(.*)$ modules/companies/companies_profile.php?id=$1 RewriteRule ^(.*)/$ modules/companies/companies_profile.php?id=$1 但是,这两个规则有冲突,导致用户页面也被引导到companies_profile.php因为companies_profile.php的规则还包含地址中的用户简档页面。 更新:我也使用[L]标志,不工作…: #Members Profile Page RewriteRule ^users/(.*)$ modules/members/members_profile.php?id=$1 [L] RewriteRule ^users/(.*)/$ modules/members/members_profile.php?id=$1 [L] #Companies Profile Page RewriteRule ^(.*)$ modules/companies/companies_profile.php?id=$1 RewriteRule ^(.*)/$ modules/companies/companies_profile.php?id=$1 不过,它正在加载companies_profile.php像/users/etcurl。 我怎么能解决这个问题? 谢谢你的帮助

重写规则(删除.php)和旧的redirect301不工作?

我没有编辑.htaccess的经验 我想 redirect非www到www。 删除.php扩展名 设置一个自定义的404页面 我设法做到这一点(寻找在networking和serverfault.com解决scheme),但现在看来,我的旧的redirect301扩展名为.php不再工作: redirect301 /download.php /features.php 我怎么能解决它? 谢谢! RewriteEngine On RewriteCond %{HTTP_HOST} !^www\. RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1 [R=301,L] Options +FollowSymlinks -MultiViews RewriteEngine on RewriteCond %{THE_REQUEST} ^GET\s.+\.php [NC] RewriteRule ^(.+)\.php$ /$1 [NE,R=301,L,NC] RewriteCond %{REQUEST_URI} !\.php$ [NC] RewriteCond %{REQUEST_FILENAME}.php -f RewriteRule . %{REQUEST_URI}.php [L] Options +FollowSymlinks ErrorDocument 404 /404 RewriteEngine on

使用htaccess文件将https地址redirect到相应的http地址

我的情况是,我为一个客户做了一个新的网站,其url格式是http://newsite.com 。 客户的旧网站使用SSL,并具有URL格式https://www.oldsite.co.uk 。 SSL在新网站上不是必需的,因此尚未被使用。 旧网站在search引擎中的排名很好,因此,客户希望使用301redirect来捕获针对旧网页的任何请求,并将其转移到新网站上的等效页面上。 旧网站上的/contact.phpredirect到新的联系页面。 问题是,所有的search引擎已经索引每个url的https://版本,我需要redirect到一个非SSL,标准的http:// URL。 简而言之,我需要的是在前面用https://捕获任何传入的URL,并以某种方式改变它以查找此URL的http://版本。 我的.htaccess文件的内容: RewriteEngine on RewriteCond %{HTTPS} on RewriteCond %{HTTP_HOST} ^nielbally\.co\.uk$ [OR] RewriteCond %{HTTP_HOST} ^www\.nielbally\.co\.uk$ RewriteRule ^/?$ "http\:\/\/artcourseswales\.com\/" [R=301,L]