简体   繁体   English

如何设置Apache mod_rewrite重定向规则?

[英]How to set up Apache mod_rewrite redirect rules?

I am not quite familiar with Apache settings. 我对Apache设置不太熟悉。 I need to make website loading sub-directory content except one page. 我需要使网站加载除一页以外的子目录内容。

Currently got a website and need to make all calls to http://www.domain.com & http://domain.com load contents from http://www.domain.com/subfolder (but looks like http://www.domain.com ) 目前有一个网站,需要进行所有对http://www.domain.comhttp://domain.com的调用,才能从http://www.domain.com/subfolder加载内容(但看起来像http:// www.domain.com

Only except the http://www.domain.com/checkout page, this one page should redirect to https://www.domain.com/checkout for secure checkout http://www.domain.com/checkout页除外,此页面应重定向到https://www.domain.com/checkout进行安全签出

The current mod_rewrite shown as below: 当前的mod_rewrite如下图所示:

RewriteEngine on

RewriteRule ^$ domain/index.php [L]
RewriteCond %{DOCUMENT_ROOT}/domain%{REQUEST_URI} -f
RewriteRule .* domain/$0 [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule .* domain/index.php?q=$0 [QSA]

RewriteCond %{HTTP_REFERER} !^$
RewriteCond %{HTTP_REFERER} !^http://domain.com.au/.*$      [NC]
RewriteCond %{HTTP_REFERER} !^http://domain.com.au$      [NC]
RewriteCond %{HTTP_REFERER} !^http://www.domain.com.au/.*$      [NC]
RewriteCond %{HTTP_REFERER} !^http://www.domain.com.au$      [NC]
RewriteRule .*\.(jpg|jpeg|gif|png|bmp)$ http://www.domain.com.au [R,NC]

Open the file named .htaccess in the root of your webserver and add following lines of code: 在您的网络服务器的根目录中打开名为.htaccess的文件,并添加以下代码行:

RewriteEngine On

RewriteCond %{HTTP_HOST} ^yourdomain.com [NC]
RewriteRule ^(.*)$ http://www.yourdomain.com/$1 [R=301,L]

RewriteCond %{SERVER_PORT} 80
RewriteRule ^checkout/(.*)$ https://www.yourdomain.com/checkout/$1 [R=301,L]

RewriteCond %{HTTP_HOST} ^www.yourdomain.com [NC]
RewriteCond %{REQUEST_URI} !^/subfolder/
RewriteCond %{REQUEST_URI} !^/checkout/
RewriteRule ^(.*)$ /subfolder/$1 [NE,L,QSA]

rewrite for your complete .htaccess-file (check if this works, then I'll delete the previous code): 重写完整的.htaccess文件(检查是否可行,然后删除之前的代码):

RewriteRule ^$ subfolder/index.php [QSA,L]

RewriteCond %{HTTP_REFERER} !^$
RewriteCond %{HTTP_REFERER} !^http://(www\.)?yourdomain.com [NC]
RewriteRule .*\.(jpg|jpeg|gif|png|bmp)$ http://www.yourdomain.com [NC]

RewriteCond %{HTTP_HOST} ^yourdomain.com [NC]
RewriteRule ^(.*)$ http://www.yourdomain.com/$1 [R=301,L]

RewriteCond %{SERVER_PORT} 80
RewriteRule ^checkout/(.*)$ https://www.yourdomain.com/checkout/$1 [R=301,L]

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^subfolder/(.*) /subfolder/index.php?q=$1 [L,QSA]

RewriteCond %{HTTP_HOST} ^www.yourdomain.com [NC]
RewriteCond %{REQUEST_URI} !^/subfolder/
RewriteCond %{REQUEST_URI} !^/checkout/
RewriteRule ^(.*)$ /subfolder/$1 [NE,L,QSA]

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM