0

http://example.com/index.php?path=controller/functionへの URLをマスクしたいhttp://example.com/controller/functionfunction存在する必要はありません。

htaccessファイルでこれを行うにはどうすればよいですか?

以下は動作しません。

RewriteRule ^/?assets/(.*)$ assets/$1 [L] # directory for CSS, images, and JavaScript
RewriteRule ^$ /index [redirect]
RewriteRule ^([a-zA-Z]+)/?([a-zA-Z/]*)$ index.php?path=$1/$2 [L]

現在、http://example.com/controller/functionブラウザで入力すると 404 エラーが発生しますが、入力http://example.com/index.php?path=controller/functionは機能します。

ありがとう!

4

1 に答える 1

6

あなたはこれを試すことができます:

RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_URI} !index\.php [NC]
RewriteRule ^([^/]+)(.*)?$ index.php?path=$1$2   [L]

内部的にマッピングします

http://example.com/var1/var2

に:

http://example.com/index.php?path=var1/var2

着信する末尾のスラッシュの動作を維持し、var2オプションです。

于 2013-01-23T05:05:18.287 に答える