Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/278.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/regex/18.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 用.htaccess或其他东西替换URL?_Php_Regex_Apache_.htaccess_Mod Rewrite - Fatal编程技术网

Php 用.htaccess或其他东西替换URL?

Php 用.htaccess或其他东西替换URL?,php,regex,apache,.htaccess,mod-rewrite,Php,Regex,Apache,.htaccess,Mod Rewrite,我见过一些网站用其他东西取代了原来的URL。示例:而不是使用http://url.com/profile/index.php?username=USERNAME他们正在使用http://url.com/profile/USERNAME 如何执行此操作?通过httpd.conf启用mod_rewrite和.htaccess,然后将此代码放在文档根目录下的.htaccess中: Options +FollowSymLinks -MultiViews # Turn mod_rewrite on Rew

我见过一些网站用其他东西取代了原来的URL。示例:而不是使用
http://url.com/profile/index.php?username=USERNAME
他们正在使用
http://url.com/profile/USERNAME


如何执行此操作?

通过
httpd.conf
启用mod_rewrite和.htaccess,然后将此代码放在
文档根目录下的
.htaccess
中:

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

RewriteRule ^(profile)/([^/.]+)/?$ /$1/index.php?username=$2 [L,QSA,NC]