0

お役に立てれば幸いです。htaccess ファイルを書き込もうとしているのですが、次のようにします。

1) www にリダイレクトします。住所

2) URL から .php を削除する

3) ファイルが存在しない場合は、filechecker.php?page=filename を使用します。


1 できること

RewriteCond %{HTTP_HOST} ^example.com$

RewriteRule (.*) http://www.example.com/ $1 [R=301,L]


2) 私はできる

RewriteCond %{SCRIPT_FILENAME}.php -f

RewriteRule [^/]$ %{REQUEST_URI}.php [QSA,L]


3) 思った

RewriteCond %{REQUEST_FILENAME}.php !-f

RewriteRule ^([^/]*)$ filechecker.php?page=$1 [QSA,L]

動作しますが、何らかの理由で、ページが実際に存在するという事実を無視しています。


マークを助けてくれることを願っています

4

1 に答える 1

0

2 のソリューションはループしますが、簡単に修正できます。パート 2 と 3 のファイルに次の行に沿って何かを貼り付けます。

#If the Browser request contains a .php, instruct the browser to remove it.
RewriteCond %{THE_REQUEST}      \.php      [NC]
RewriteRule ^/?(.*)\.php$       http://%{HTTP_HOST}/$1         [R=301,NC,L]

#If a request is received for a non file-system object, that doesn't have a .php suffix, then store the full path, filename, and URI in a variables with that extention.
RewriteCond %{SCRIPT_FILENAME} !-d
RewriteCond %{SCRIPT_FILENAME} !-s
RewriteCond %{SCRIPT_FILENAME} !-f
RewriteCond %{SCRIPT_FILENAME} !^\.php$  [NC]
RewriteRule ([^/]+)$      -  [E=testScript:%{SCRIPT_FILENAME}.php,E=testFile:$1.php,E=testURI:%{REQUEST_URI}.php]

#See if the file exists with a .php extention, if it does internally rewrite
RewriteCond %{ENV:testScript} -s  [OR]
RewriteCond %{ENV:testScript} -f
RewriteRule .*              %{ENV:testURI} [L]

#Else if a ENV:testDile is set, then pass the name to the php script
RewriteCond %{ENV:testFile} !^$
RewriteRule .*               /filechecker.php?page=%{ENV:testFile} [L]

参考までに: Apache mod_rewriteのドキュメントは一読の価値があります。上記のルールが何をするものなのか不明な場合、またはもう少し抽象的な内容が必要な場合は、次の投稿を検討してください。

于 2012-11-14T03:27:07.770 に答える