0

まず、下手な英語で申し訳ありません。

Form Get から生成された URL を書き換えてリダイレクトしようとしています。

私のURLは次のようなものです:

http://www.mysite.com/properties?action=search&agreement=for-rent&category=my-category&type=&zone=my-zone&city=my-city

そして、私はこの .htaccess を構成しました:

11. RewriteCond %{QUERY_STRING} ^action=(?:[a-zA-Z\-]*)&(?:.*)=([a-zA-Z\-]*)&(?:.*)=([a-zA-Z\-]*)&(?:.*)=([a-zA-Z\-]*)&(?:.*)=([a-zA-Z\-]*)&(?:.*)=([a-zA-Z\-]*)$
12. RewriteRule (.*) %{REQUEST_URI}/%1/%2/%3/%4/%5/? [R=301,L]

したがって、基本的にすべてのリクエストは index.php に直接送信されます。

21. RewriteCond %{REQUEST_URI} !index\.php|resources|hidden
22. RewriteRule ^(.*)$ index.php/$1 [L]

すべて動作しますが、クエリ文字列に空の値がある場合に問題が発生し、ルールで二重スラッシュが追加され、上記の URL (たとえば、whit &type=&zone=my-zone... type have empty value) が次のように変換されます。

http://www.mysite.com/for-rent/my-category//my-zone/my-city/

問題は、クエリ文字列に 1 つ以上の空の値がある場合に生成された二重スラッシュを .htaccess で削除するにはどうすればよいですか?

ありがとう

4

1 に答える 1

1

Easiest is to do another redirect (not real pretty as it requires two 301's).

RewriteCond %{THE_REQUEST} //
RewriteRule .* $0 [R=301,L]

The fun part is that when the url is loaded with a double slash in it, mod_rewrite will automatically remove this. So as you can see above you'll just have to rewrite the url to itself, kind of.

于 2012-05-25T17:02:20.233 に答える