替换本地页面上的 URL
Replacing the URL on a local page
所以我正在为学校作业构建一个页面,我想更改 URL 以匹配任何内容。
http://localhost/meet/myprofile.php
我想改成
http://localhost/meet/(username here)
或
http://localhost/meet/login
我希望用户更改为数据库中写入的任何内容,但是例如让我们说 $_SESSION['username']
我之前正在搜索,但无法完成。
我建议使用 .htaacces 重写规则。基本思想是,它接受给定的 url 并在其上内部映射 php 文件。它支持 $_GET 请求,因此你可以创建 URL like
http://webpage.com/article/85/
将用 .像这样的 htaccess
http://webpage.com/article.php?id=85
使用这样的规则
RewriteEngine on
RewriteRule ^article//$ article.php?id= [QSA]
这是一个非常好的教程,它是如何工作的。希望你能设法解决它,如果没有,请随时发表评论并询问。 ;)
https://www.addedbytes.com/articles/for-beginners/url-rewriting-for-beginners/
我不确定您是否可以使用 session 但可以在 htaccess 中使用以下代码使用 cookie。假设,您已经将 cookie 用户名设置为 Tommy
RewriteEngine on
RewriteCond %{HTTP_COOKIE} username=(\w+)
RewriteRule meet/myprofile.php /meet/%1
然后 /meet/myprofile.php
将被重定向到 /meet/Tommy
所以我正在为学校作业构建一个页面,我想更改 URL 以匹配任何内容。
http://localhost/meet/myprofile.php
我想改成
http://localhost/meet/(username here)
或
http://localhost/meet/login
我希望用户更改为数据库中写入的任何内容,但是例如让我们说 $_SESSION['username']
我之前正在搜索,但无法完成。
我建议使用 .htaacces 重写规则。基本思想是,它接受给定的 url 并在其上内部映射 php 文件。它支持 $_GET 请求,因此你可以创建 URL like
http://webpage.com/article/85/
将用 .像这样的 htaccess
http://webpage.com/article.php?id=85
使用这样的规则
RewriteEngine on
RewriteRule ^article//$ article.php?id= [QSA]
这是一个非常好的教程,它是如何工作的。希望你能设法解决它,如果没有,请随时发表评论并询问。 ;)
https://www.addedbytes.com/articles/for-beginners/url-rewriting-for-beginners/
我不确定您是否可以使用 session 但可以在 htaccess 中使用以下代码使用 cookie。假设,您已经将 cookie 用户名设置为 Tommy
RewriteEngine on
RewriteCond %{HTTP_COOKIE} username=(\w+)
RewriteRule meet/myprofile.php /meet/%1
然后 /meet/myprofile.php
将被重定向到 /meet/Tommy