I am making a profile system, and using localhost/profiles?user=ryr11
works, and I tried to use
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^\.]+)$ $1.php [NC,L]
RewriteRule ^profiles/(.+)$ profiles.php?user=$1 [L,QSA]
so that I can use localhost/profiles/ryr11
, but when I do that I no longer get a 404 error, but using $_GET['user']
no longer works.
Try this:
RewriteEngine On
RewriteCond %{SCRIPT_FILENAME} !-d
RewriteCond %{SCRIPT_FILENAME} !-f
RewriteRule ^profiles/([a-zA-Z0-9_.-]+)/?$ profiles.php?user=$1 [L,NC,QSA]
Keep your rules like this:
Options -MultiViews
RewriteEngine On
RewriteBase /
RewriteRule ^profiles/(.+)$ profiles.php?user=$1 [L,QSA,NC]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{DOCUMENT_ROOT}/$1.php -f [NC]
RewriteRule ^(.+?)/?$ $1.php [NC,L]
You need to decode the url again in order to remove - from it.
Use this
$user = $_GET['user'];
$postTitle = str_replace("-", " ", $user);
This should work again.
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.