htaccess的重写GET变量的URL,但仍然有机会获得他们有机会、重写、变量、但仍然

2023-09-02 00:58:53 作者:奈何桥上唱咆哮。

我试图把东西在我的.htaccess文件中,这将让我改变了以下网址:

I am trying to put something in my .htaccess file that will allow me to change the following URL:

http://www.mysite.com/profile?user=theuser

要这样的:

http://www.mysite.com/profile/theuser

而在页面上,仍然可以做一些事情,如:

But in the page, still be able to do something like:

echo $_GET['user']; // echos "theuser"

这可能吗?我将如何做到这一点?

Is this possible? How would I do this?

注:我想获得的URL地址栏中显示 http://www.mysite.com/profile/theuser

NOTE: I am trying to get the URL in the address bar to show http://www.mysite.com/profile/theuser

推荐答案

的httpd.conf 启用了mod_rewrite和.htaccess,然后把这个code在< $ C C>的.htaccess $ DOCUMENT_ROOT 目录下:

Enable mod_rewrite and .htaccess through httpd.conf and then put this code in your .htaccess under DOCUMENT_ROOT directory:

Options +FollowSymLinks -MultiViews
# Turn mod_rewrite on
RewriteEngine On
RewriteBase /

RewriteRule ^(profile)/(theuser)/?$ $1?user=$2 [L,QSA,NC]