2016-11-07 51 views
1

1)我有一個htaccess的重寫誰的用戶配置文件。httacces衝突改寫用戶的配置文件和用戶帖子

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

http://example.com/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 

http://example.com/post?id=12345678

它可以用在未來httaccess

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

3)每個人都工作良好的隔離,但我想這兩個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] 

還要注意,在正則表達式使用/?$,你可以結合2個規則爲一體。

+0

我仍然在做這個工作,謝謝。 – Doe

+0

但是'-d'和'-f'是什麼意思? – Doe

+0

正如上述規則所述的評論所述。 '-d'檢測目錄,'-f'檢測現有文件。 – anubhava

相關問題