简体   繁体   中英

How to remove file name from url using .htaccess?

I have follwoing url's

http://127.1.1.1/mysite/username/admin

I want to display like this url

http://127.1.1.1/mysite/admin

Here 'username' is file name.

How it can be possible?

Store this .htaccess to http://127.1.1.1/mysite/.htaccess :

RewriteEngine on /mysite/
RewriteRule ^(.*)$ username/$1 [r=301,L]

http://127.1.1.1/mysite/admin -> http://127.1.1.1/mysite/username/admin http://127.1.1.1/mysite/admin.php?some=value -> http://127.1.1.1/mysite/username/admin.php?some=value

username.php

RewriteEngine on /mysite/
RewriteRule ^(.*)$ username.php?requested-file=$1 [r=301,L]

http://127.1.1.1/mysite/admin -> http://127.1.1.1/mysite/username.php?requested-file=admin

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