2011-07-03 36 views
0

我有一個問題rewritting /認證/ view_profile用戶=(用戶名)到myurl.com/profil/(username)的.htaccess PHP改寫

現在我的.htaccess文件是:?

RewriteEngine On 
#Rewrite /view.php?vis=id to /opslag/vis/id 
#RewriteRule ^opslag/vis/(\d+)$ /opslag/view.php?vis=$1 [NC,QSA,L] 

#Rewrite authentication/view_profile.php?user=* to profil/* 
RewriteRule ^profil/(\d+)$ /authentication/view_profile.php?user=$1 [NC,QSA,L] 

#Remove index.php 
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /.*index\.php\ HTTP/ 
RewriteRule ^(.*)index\.php$ /$1 [R=301,L] 

#Remove /page/ 
RewriteCond %{REQUEST_FILENAME} !-f 
RewriteCond %{REQUEST_FILENAME} !-d 
RewriteRule ^([^/\.]+)/?$ index.php?page=$1 [L] 

我已經使用規則重寫一個又一個,這就是「#Rewrite view.php可見= id來/ opslag /可見/ ID

現在我的網址是這樣的:?

<a href='/profil/$_SESSION[username]'>Vis profil</a> 

我希望你想幫助我。

如果你需要一些詳細信息,請告訴我..:O)

+0

這將是很好的知道什麼是行不通的。你從服務器收到錯誤嗎? – enyo

+0

@Enyo當我有這些設置時,它只是說:未找到 在此服務器上找不到請求的URL/profil /(用戶名)。 – skolind

回答

4

用這個來代替:如果由數字僅(\d+)

RewriteRule ^profil/([^/]+)$ /authentication/view_profile.php?user=$1 [NC,QSA,L] 

你的規則可以只接受用戶名。這一個([^/]+)將接受任何字符(/,這是一個文件夾分隔符除外)。

P.S. 如果您打算定期使用.htaccess和URL重寫規則,請考慮閱讀此Introduction to regular expressions and mod_rewrite

+0

感謝您的幫助,並感謝您的鏈接:o)我會將您標記爲正確的答案。 – skolind