1

このhtaccessの何が問題になっていますか?「www.mysite.com/?bla=bla」のような疑問符が付いているものをすべて「www.mysite.com/router.php?bla=bla」にリダイレクトしようとしています。

AddDefaultCharset UTF-8
RewriteEngine On
RewriteRule ^([\w]{1,7})$ short.php?p=$1 [L]
RewriteRule ^([\w]+)\.html$ html/$1.html [L]
RewriteRule ^([\w]+)\.php$ php/$1.php [L]
RewriteRule ^\?(.+)$ router.php?$1 [L]

各ルールは、最後のルールを除いて機能します。最後のルールは次のようになります。

Forbidden

You don't have permission to access / on this server.

Additionally, a 404 Not Found error was encountered while trying to use an ErrorDocument to handle the request.
4

1 に答える 1

2

内のクエリ文字列にアクセスすることはできませんRewriteRule。代わりに、RewriteCondそれを一致させるために使用します。をその位置で使用する?と、正規表現の特殊文字として扱われます。

代わりに次を使用します。

# Prevent redirect loop
# Place above all other rules
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d

# Non-empty querystring goes to router
RewriteCond %{QUERY_STRING} ^(.+)
# Rewrite to router appending existing querystring (QSA)
RewriteRule ^/?$ router.php [L,QSA]

補遺:

次のコマンドを使用して、ルーターが php ディレクトリに入らないようにします。

RewriteCond %{REQUEST_FILENAME} !^router\.php
RewriteRule ^([\w]+)\.php$ php/$1.php [L]
于 2012-05-17T15:26:47.497 に答える