Apache 使用.htaccess.php重写url
我想把用户名作为url的一部分,url应该是这样的Apache 使用.htaccess.php重写url,apache,.htaccess,url,Apache,.htaccess,Url,我想把用户名作为url的一部分,url应该是这样的 domanin.com/username/profile.html domanin.com/username/events.html domanin.com/username/messages.html 你能指导我怎么做吗 如果我注册为阿里,那么阿里应该是我的url的一部分 domain.com/ali/profile.html domain.com/ali/events.html这就是我在我的网站上做这件事的方式,用户可以在这里注册,它是用p
domanin.com/username/profile.html
domanin.com/username/events.html
domanin.com/username/messages.html
你能指导我怎么做吗
如果我注册为阿里,那么阿里应该是我的url的一部分
domain.com/ali/profile.html
domain.com/ali/events.html
这就是我在我的网站上做这件事的方式,用户可以在这里注册,它是用php编写的,但可以修改以获得您想要的内容
RewriteEngine On
# Full path
RewriteBase /
# Rewrite all php files
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.php -f
RewriteRule ^(.*)$ $1.php
# Rewrite the user profile pages
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^user/([a-zA-Z0-9_-]+)$ profile.php?user=$1
RewriteRule ^user/([a-zA-Z0-9_-]+)/$ profile.php?user=$1
第一个重写基是站点的根目录。“重写所有php文件”下的第二个重写集将从文件中删除所有.php文件扩展名
第三个重写集是您感兴趣的。Profile.php是用户配置文件,而?user=$1是注册用户名。当调用URL www.domain.com/user/userName/时,它实际上会从页面profile.php?user=userName获取数据
您必须对其进行一点修改,以使其符合您的要求,就像我的php一样,但谷歌上到处都有关于如何做到这一点的教程。你希望重写的url是什么样子,实际的url是什么?请详细说明example@VarinderSingh用户名将替换为注册时选择该用户名的用户的用户名。本网站提供了一个使用.htaccess重写url的不错指南。如果它没有你想要的,只要谷歌.htaccess mod_重写,你就会得到大量的结果。