开发者

htacces rewrite url - remove folder name from url

I'm tryng to make an htaccess url rewrite for this cases:

www.website.com/index.php/admin/something => www.website.com/admin/something
www.website.com/index.php/w开发者_C百科ebsite/something => www.website.com/something
www.website.com/index.php/login/something => www.website.com/login/something

note: "something" can be "something1/something2/something3" or "something1/something2" or "something"

I can cut "index.php" with:

RewriteEngine on

RewriteCond $1 !^(index\.php|resources|robots\.txt)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L,QSA]

but I can't found a way to remove only "website/" and not "admin/" and "login/" leaving the rest of url.


If taking this approach you will probably have to specify each possible input reference that should not be mapped to your 'website' controller and remap it to index.php/$1 and treat every other request like it is a method of the website controller, mapping it to index.php/website/$1

Something like the below will map anything starting with admin or login to index.php and everything else to the website controller:

RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} ^admin.*
RewriteCond %{REQUEST_URI} ^login.*
RewriteRule ^(.*)$ index.php?/$1 [L]

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI}
RewriteRule ^(.*)$ /index.php?/website/$1 [L]
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜