2014-01-05 30 views
2

我用htacess刪除php擴展,它的工作,但我也有一個頁面稱爲配置文件,我縮短,但使網頁名稱被視爲一個配置文件用戶名,是否有一個解決這個問題的方法?htaccess在兩個不同的頁面中刪除擴展

我想要的結果是這樣的:

localhost/path_folder/index.phplocalhost/path_folder/index

localhost/path_folder/profile?username=namelocalhost/path_folder/name

和我的去除擴展htaccess代碼:

RewriteEngine On 
RewriteCond %{REQUEST_FILENAME} !-f 
RewriteRule ^([^\.]+)$ $1.php [NC] 

,並在個人資料頁面的代碼是:

RewriteEngine On 
RewriteCond %{REQUEST_FILENAME} !-f 
RewriteCond %{REQUEST_FILENAME} !-d 
RewriteRule ^(.*)$ /path_folder/profile.php?username=$1 

回答

1

RewriteEngine On 

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

## if PHP file not found then load profile page 
RewriteCond %{REQUEST_FILENAME} !-f 
RewriteCond %{REQUEST_FILENAME} !-d 
RewriteRule ^(.+?)/?$ /path_folder/profile.php?username=$1 [L,QSA] 
+0

非常感謝您的完美工作。 –

+0

不客氣,很高興它解決了。 – anubhava

0

如果要刪除的文件擴展名

RewriteEngine On 
RewriteRule ^path_folder/([^/]*)$ path_folder/$1.php [L]

縮短的URL將這個代碼在你DOCUMENT_ROOT/.htaccess文件的UserProfiles

 
RewriteEngine On 
RewriteRule ^path_folder/profile/([^/]*)$ path_folder/profile?username=$1 [L] 
+0

問題是,htaccess將頁面名稱作爲配置文件用戶名 –

+0

是的,它的確如此。 你想要那樣的東西嗎? path_folder/profile/username – Alan

+0

是的,我想到了,但有沒有一種方式,路徑配置文件不顯示在網址中? –