Htaccess干净的用户配置文件URL不重定向

时间:2014-06-16 23:38:01

标签: regex apache .htaccess mod-rewrite

我无法获得干净的用户个人资料网址。我已经尝试了一切! 我想重定向

http://localhost/test/profile?username=gadgetster

http://localhost/test/profile/gadgetster

这是我的尝试:

Options -Indexes -MultiViews +FollowSymlinks
RewriteEngine On
RewriteBase /test/

RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{DOCUMENT_ROOT}/%{REQUEST_URI}\.php -f [NC]
RewriteRule ^(.+?)/?$ $1.php [L]

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^profile/(.+)$ profile.php?username=$1 [L,NC,QSA]

为什么这不起作用?

1 个答案:

答案 0 :(得分:2)

有这样的话:

Options -Indexes -MultiViews +FollowSymlinks
RewriteEngine On
RewriteBase /test/

RewriteCond %{THE_REQUEST} /profile\.php\?username=([^\s&]+) [NC]
RewriteRule ^ profile/%1? [R=302,L]

RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^ - [L]

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

RewriteCond %{DOCUMENT_ROOT}/%{REQUEST_URI}\.php -f [NC]
RewriteRule ^(.+?)/?$ $1.php [L]

确保.htaccess中没有/test/profile/