I am getting this url https://domain.com/user.php/123456
. I want to redirect this url to https://domain.com/user/123456
using htaccess.
My htaccess code:
RewriteEngine On
RewriteCond %{HTTPS} off
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} [R,L]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^./]+)/(.+)$ $1.php/$2 [L]
I am internally processing this url by exploding the ("/") and getting the user information based on the query string id.
Any help would be appreciated. Thanks in advance.
Try the following Rules.
RewriteEngine on
#1--redirect from "user.php/foo" to "user/foo"
RewriteCond %{THE_REQUEST} /user\.php/([^\s]+) [NC]
RewriteRule ^ /user/%1 [L,R]
#2--rewrite "user/foo" to "user.php/foo"
RewriteRule ^user/(.+)$ /user.php/$1 [NC,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.