2015-06-07 212 views
1

我想知道我怎麼能全部重定向訪問者誰在訪問以下地址:的.htaccess重寫 - 重定向頁面

https://example.com/anypagehttps://example.com/search/anypage

它不能重定向的人誰已經在https://example.com/search/anypage避免循環。這是我目前的.htaccess:

Options -Indexes +FollowSymLinks 

RewriteEngine On 
RewriteBase/

RewriteCond %{HTTPS} off 
RewriteRule .* https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301] 

RewriteCond %{REQUEST_FILENAME} !-d 
RewriteCond %{REQUEST_FILENAME} !-f 

<IfModule mod_php5.c> 
    RewriteRule ^(.*)$ index.php/$1 [L]  
</IfModule>  

# the following is for rewritting under FastCGI 
<IfModule !mod_php5.c>  
    RewriteRule ^(.*)$ index.php?/$1 [L] 
</IfModule> 

感謝

回答

1

您可以在DOCUMENT_ROOT/.htaccess文件中使用此代碼:

Options -Indexes +FollowSymLinks  
RewriteEngine On 
RewriteBase/

RewriteCond %{HTTPS} off 
RewriteRule^https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301] 

RewriteCond %{REQUEST_FILENAME} !-d 
RewriteCond %{REQUEST_FILENAME} !-f 
RewriteCond %{THE_REQUEST} !/search/ [NC] 
RewriteRule ^(.*)$ search/$1 [L,R] 

RewriteCond %{REQUEST_FILENAME} !-d 
RewriteCond %{REQUEST_FILENAME} !-f 

<IfModule mod_php5.c> 
    RewriteRule ^(.*)$ index.php/$1 [L]  
</IfModule>  

# the following is for rewritting under FastCGI 
<IfModule !mod_php5.c>  
    RewriteRule ^(.*)$ index.php?/$1 [L] 
</IfModule> 
+0

您好,感謝您的回答,但它ruturns錯誤500.我使用.htaccess之前,我更新了我的問題,並提供了更多細節。 –

+1

好吧現在嘗試我的更新規則。 – anubhava

+1

Works perfeclty!非常感謝你! –