繁体   English   中英

用户的漂亮URL链接

[英]Pretty URL Links for Users

我正在尝试从yourwebsite / profile.php?username = funusername将URL 设为 yourwebsite / funusername 我已经尝试过.htaccess像:

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

(我那里也有代码,可以将.php从页面中删除)。 我对.htaccess经验不足,因此非常感谢您的帮助。

奖励:如何在链接中引用此URL? <a href="profileurl">

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

这是一个工作示例:

yourwebsite / 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标签。

另外,如果yourwebsite / account.php中有<!doctype html>标记,也将其删除。

例如:

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

您也可以使用iframe进行操作,但这就是我的操作方式

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM