简体   繁体   中英

htaccess rewrite url to hide php question mark

my url format mysite/profile/?theusername with hide php extension, im trying to hide question mark in url so the url will like mysite/profile/theusername , looked up few posts about what i should do is add external redirect then internal forward in htaccess, tried lot of code still can't get it work. this is what i have now:

Options +FollowSymLinks -MultiViews
RewriteEngine On
RewriteBase /   

# Resolve .php file for extensionless php urls
RewriteRule ^([^/.]+)$ $1.php [L]

Keep your .htaccess like this:

Options +FollowSymLinks -MultiViews
RewriteEngine On
RewriteBase /profile/

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

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

# php hiding
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule ^(.+?)/?$ $1.php [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