2014-04-11 43 views
0

我無法弄清楚如何將這個URL改寫爲頁面和用戶配置文件的規則

http://localhost/site/page.php?id=[pagetitle]

改寫爲

http://localhost/site/page/title

和 用戶配置文件

http://localhost/site/profile.php?username=username


http://localhost/site/profile/username

這是我使用的代碼:

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

RewriteEngine敘述在 的RewriteCond%{} REQUEST_FILENAME!-f 的RewriteCond%{} REQUEST_FILENAME!-d 重寫規則^ profile(。*)$ profile.php?username = $ 1 RewriteRule ^( 。*)$ page.php?title = $ 1 – Dinho

+0

你可以用它更新問題。它可能會給你一個更積極的分數 – Philibobby

回答

1

這將改寫輸入本地主機/網站/網頁/標題loacalhost /網站/網頁.php?id = [pagetitle]

RewriteRule ^localhost/site/(.+)$ site/page.php?id=$1 
    RewriteRule ^localhost/site/profile/(.+)$ site/profile.php?username=$1 
+0

對象未找到!不工作 – Dinho

+0

RewriteRule ^(。+)$ profile.php?用戶名= $ 1這是爲本地主機/網站/ useranme工作,我想移動到本地/網站/配置文件/用戶名 – Dinho

0

This s HOULD工作

重寫規則^([A-ZA-Z0-9 _-] +)$ profile.php?用戶名= $ 1

重寫規則^([A-ZA-Z0-9 _-] +)/ $ profile.php?用戶名= $ 1

0
RewriteCond %{REQUEST_FILENAME} !-f 
RewriteCond %{REQUEST_FILENAME} !-d 
RewriteRule ^profile/(.*)$ profile.php?username=$1 
RewriteCond %{REQUEST_FILENAME} !-f 
RewriteCond %{REQUEST_FILENAME} !-d 
RewriteRule ^page/(.*)$ page.php?title=$1 

假定在/網站/目錄下的.htaccess

+0

當我用這個我的css無法加載 – Dinho

+0

@Dinho提供一些鏈接的例子。所有鏈接必須相對於根,即正斜槓。 – Deadooshka

相關問題