我有以下.htaccess文件:從URL刪除.PHP有例外(htaccess的)
RewriteEngine On
RewriteRule ^([a-zA-Z0-9_-]+)$ account.php?username=$1
這基本上成爲我的用戶配置文件,以便像Twitter有人可以只輸入:url.com/theirusername
但是我想讓某些頁面像/ home不會導致配置文件,而是一個不同的.php頁面,最後沒有.php。
任何人都可以想辦法做到這一點?
謝謝!
我有以下.htaccess文件:從URL刪除.PHP有例外(htaccess的)
RewriteEngine On
RewriteRule ^([a-zA-Z0-9_-]+)$ account.php?username=$1
這基本上成爲我的用戶配置文件,以便像Twitter有人可以只輸入:url.com/theirusername
但是我想讓某些頁面像/ home不會導致配置文件,而是一個不同的.php頁面,最後沒有.php。
任何人都可以想辦法做到這一點?
謝謝!
你可以有另一種策略,這條之前添加.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]
這工作就像一個魅力,謝謝! – Ben