2016-07-15 86 views
1

我有以下.htaccess文件:從URL刪除.PHP有例外(htaccess的)

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

這基本上成爲我的用戶配置文件,以便像Twitter有人可以只輸入:url.com/theirusername

但是我想讓某些頁面像/ home不會導致配置文件,而是一個不同的.php頁面,最後沒有.php。

任何人都可以想辦法做到這一點?

謝謝!

回答

2

你可以有另一種策略,這條之前添加.php

RewriteEngine On 

# To internally redirect file to file.php 
RewriteCond %{REQUEST_FILENAME} !-d 
RewriteCond %{REQUEST_FILENAME}.php -f 
RewriteRule ^(.+?)/?$ $1.php [L] 

# handle profile URLs  
RewriteCond %{REQUEST_FILENAME} !-d 
RewriteRule ^([\w-]+)/?$ account.php?username=$1 [L,QSA] 
+1

這工作就像一個魅力,謝謝! – Ben

1

只需添加更多的規則,以匹配所有其他網頁,爲用戶名的規則之前所說的那樣。

RewriteEngine On 
RewriteRule ^home$ home.php 
RewriteRule ^contact$ contact.php 
RewriteRule ^([a-zA-Z0-9_-]+)$ account.php?username=$1 
+1

感謝您花時間回答。我在最後使用了第一個答案。 – Ben

+0

n1。第一個答案非常好,它是一個通用的解決方案。 – Oliver