用户的漂亮网址链接

时间:2016-06-27 20:22:39

标签: php

我正在尝试从 yourwebsite / profile.php?username = funusername 中创建我的网址 yourwebsite / funusername 。我试过像.htaccess:

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^\.]+)$ $1.php [NC,L]
RewriteRule ^/([^/]+)$ profile.php?username=$1

(我也有代码在那里使.php从我的页面中取出)。我对.htaccess非常缺乏经验,所以非常感谢任何帮助。

加分:如何在链接中引用此网址?例如<a href="profileurl">

1 个答案:

答案 0 :(得分:0)

您可以使用jQuery load创建页面yourwebsite / funusername / index.html并加载yourwebsite / profile.php?username = funusername。

这是一个有效的例子:

您的网站代码/ funnyusername / index.html:

<!doctype html>
<html>
<script type="text/javascript" src="https://code.jquery.com/jquery-3.0.0.min.js"></script>
<script type="text/javascript">
$(document).ready(function()
{
  $("html").load("/path/to/profile.php?username=funnyusername");
});
</script>
</html>

然后删除yourwebsite / account.php。

的html标签

此外,如果您的网站/ account.php中有<!doctype html>标记也将其删除。

E.g:

<head>
** Whatewer code you have here **
</head>
<body>
** Whatever code you have here **
</body>

您也可以使用iframe执行此操作,但我就是这样做的

相关问题