简体   繁体   中英

htaccess rewrite example.com/user.php?id=username to example.com/username

Title says it all im having trouble rewriting the following urls

The original URL: example.com/user.php?id=username

The rewritten URL: example.com/username

My .htcacess code is:

RewriteEngine On
RewriteRule ^([^/]*)$ /user.php?id=$1 [L]

What the issue?

The rewrite engine will loop, which means the rewritten URI ( /user.php ) matches the same pattern and gets applied again. Try adding some conditions:

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^/]*)$ /user.php?id=$1 [L]

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM