2014-04-11 41 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

相关问题