문제

Almost everyone has gone to Facebook. On Facebook they have a url like www.facebook.com/username but on a site that has their user structure like this: site.com/profile.php?user=username how can you rewrite the link to look like Facebook (ie: site.com/username) so that if you go to site.com/username in your browser, it will actually link to the site.com/profile.php?user=username without only looking like it is rewriting the URL while you are on the page?

도움이 되었습니까?

해결책

This should work:

RewriteEngine On
RewriteCond %{THE_REQUEST} ^(GET|POST)\ /profile\.php\?username=(.*)\ HTTP
RewriteRule ^ /%2\? [R=301,L]

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /profile.php?user=$1 [L]
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top