如何使用.htaccess制作干净的网址

时间:2014-03-14 13:21:17

标签: .htaccess

我有这个个人资料页面,会显示您的个人资料

localhost:8080/profile?username=ImSchnebz

但问题是我希望它看起来像这样:

localhost:8080/profile/ImSchnebz

我已经尝试了很多不同的答案,但是大部分都给了我404找不到或500内部服务器错误,我知道这不是你们可以帮助我的任何东西,但我之前已经问过这个问题,没有回复,所以,如果那里有人,请帮助我! :)

由于

修改

我有这段代码

RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ /profile.php?username=$1 [L,QSA]

它与localhost:8080/ImSchnebz完美配合,但我希望它是localhost:8080/profile/ImSchnebz

2 个答案:

答案 0 :(得分:0)

尝试

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

基于@Lawrence给出的链接。

答案 1 :(得分:0)

试试这个:

RewriteEngine on
RewriteBase /

RewriteRule ^profile/(.*)$ profile.php?username=$1 [L,QSA]