2016-11-07 3 views
1

1)ユーザープロファイルを書き換えるhtaccessがあります。次のコードwhith http://example.com/Ernesthttacces conflictsユーザーのプロファイルとユーザーの投稿を書き換えます。

http://example.com/account.php?p=profile&username=Ernest 

RewriteEngine On 
RewriteRule ^([a-zA-Z0-9_-]+)$ account.php?p=profile&username=$1 
RewriteRule ^([a-zA-Z0-9_-]+)/$ account.php?p=profile&username=$1 

それは良い作品...

2)、ユーザーの投稿を書き換え次httaccess

http://example.com/account.php?p=post&id=12345678 

)それは次のhttaccess

RewriteRule ^post$ account.php?p=post [QSA] 

3で動作します

http://example.com/post?id=12345678に誰もが孤立良い動作しますが、現時点では、私は、ユーザーが&投稿プロファイル書き換えられていることが1つのファイルに両方のhtaccessのコードをミックスしたいです。それは失敗する!どうやったらそれを働かせるべきですか?

答えて

0

他のルールよりも前にpostルールがあり、ファイルとディレクトリの書き換えをスキップする他のすべてのルールの前に除外ルールを設定する必要があります。

RewriteEngine On 

# skip all files and directories from rewrite rules below 
RewriteCond %{REQUEST_FILENAME} -d [OR] 
RewriteCond %{REQUEST_FILENAME} -f 
RewriteRule^- [L] 

RewriteRule ^post/?$ account.php?p=post [L,NC,QSA] 

RewriteRule ^([\w.-]+)/?$ account.php?p=profile&username=$1 [L,QSA] 

はまた、正規表現で/?$を使用することによって、あなたは1に2つのルールを組み合わせることができますことに注意してください。

+0

まだ作業中です。ありがとうございます。 – Doe

+0

しかし、 '-d'と' -f'はどういう意味ですか? – Doe

+0

このルールの上のコメントには、 '-d'はディレクトリを検出し、' -f'は既存のファイルを検出します。 – anubhava

関連する問題