2017-11-22 76 views
2

書き換えルールがありますが、ページがindex.phpでない場合にのみ書き換えルールを実行したい場合は、If文を使用してみました。私のコード、私が試みたもの.htaccess内の特定のファイル名に対してIf文を実行する

Options +FollowSymLinks 
RewriteEngine On 

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

RewriteRule ^index$ ./index.php // i did a URL rewrite for removing the .php 

<If "%{HTTP_HOST } == 'index'"> 
// do nothing here else 
</If> 
<Else> //run the code in the else statement. 
RewriteRule^profile.php [NC,L] 
RewriteRule ^profile/([0-9a-zA-Z]+) profile.php?id=$1 [NC,L] 

RewriteRule^zprofile.php [NC,L] 
RewriteRule ^zprofile/([0-9a-zA-Z]+) zprofile.php?id=$1 [NC,L] 
</Else> 
+0

実際のURLに 'index'を変更します。 – Lag

+0

@Lag応答サーバーエラー。 – Shasha

+0

@ Chris85ありがとう、ありがとう、私は本当に理解していません。 – Shasha

答えて

1

私は、以下のこの単純なコードで、不足光沢の夜の後に、それを解決したが、私は別のアプローチでそれをやった、代わりに使用のif文、私は単に私が最初のように任意の場所私のディレクトリに知っていたページを書き直し私のディレクトリに存在しないページは、URLが同じである特定のページにリダイレクトする必要があります。

Options +FollowSymLinks 

RewriteEngine On 
RewriteCond %{SCRIPT_FILENAME} !-d 
RewriteCond %{SCRIPT_FILENAME} !-f 


RewriteRule ^zindex$ zindex.php //file in the directory 

RewriteRule ^index$ index.php //file in the directory 

RewriteRule ^zprofile$ zprofile.php //file in the directory 

RewriteRule ^logout logout.php [NC] //file in the directory 


RewriteCond %{REQUEST_FILENAME} !-f //if file does not exist in directory redirect 
RewriteCond %{REQUEST_FILENAME} !-d //if file does not exist in directory redirect 
RewriteRule ^.*$ profile.php [L] //to profile.php page with the URL still being the same. 
関連する問題