内部网址重写错误404

时间:2015-09-04 00:48:55

标签: .htaccess

我想要这个网址重写? 这是我的旧网址:     http://example.com/user.php?username=philip1

新网址:     http://example.com/user/philip1/

.htaccess文件:

Options +FollowSymLinks -MultiViews
# Turn mod_rewrite on
RewriteEngine On
RewriteBase /
RewriteRule ^user\.php$ %{QUERY_STRING} [C]
RewriteRule ^username=(.*) /user/$1/? [R=301,L]

我找不到对象!或页面不存在这意味着重定向不重写。 问题: 我需要内部重写使用这个旧URL:

http://example.com/user.php?username=philip1

1 个答案:

答案 0 :(得分:0)

尝试:

Options +FollowSymLinks -MultiViews
#Turn mod_rewrite on
RewriteEngine On
RewriteBase /
#if the requsted filename is not a directory
RewriteCond %{REQUEST_FILENAME} !-d
#then rewrite "/user/foo" to "/user.php?username=foo"
RewriteRule ^user/([^/]+)/?$ /user.php?username=$1 [QSA,NC,L]