我正在尝试在我的.htaccess文件中放置一些东西,以允许我更改以下URL:
http://www.mysite.com/profile?user=theuser
像这样:
http://www.mysite.com/profile/theuser
但是在页面中,仍然可以执行以下操作:
echo $_GET['user']; // echos "theuser"
这可能吗?我该怎么做?
注意:我正在尝试获取地址栏中的 URL 以显示http://www.mysite.com/profile/theuser
通过httpd.conf
启用mod_rewrite和.htaccess,然后将此代码放在DOCUMENT_ROOT
目录下的.htaccess
中:
Options +FollowSymLinks -MultiViews
# Turn mod_rewrite on
RewriteEngine On
RewriteBase /
RewriteRule ^(profile)/(theuser)/?$ $1?user=$2 [L,QSA,NC]
是的,这就是 URL 重写的设计方式。
URL 在内部重写为
http://www.mysite.com/profile?user=theuser
格式。