开发者

URL Rewrite to remove my controller's name from the url displayed

I have this site

开发者_如何学Python

http://cjbuilders.info/welcome/home

and all the links start with

http://cjbuilders.info/welcome

How can I use mod_rewrite to just remove

/welcome/

from the url? This should be an easy one, but i struggle with mod_rewrite.


Do you know about CodeIgniter's URI Routing? Add this into your routes.php config file and it should work just fine:

$route['home'] = 'welcome/home';


This should work, IIRC:

RewriteRule ^/welcome/(.*)$ /$1 [R]

However, guessing a bit about what's going on here, if the reason for this prefix is something like a Java app server deploying an app at a context called "welcome", then the better solution is not to rewrite the URLs but to fix the backend app server to have a null context, i.e. serve at / rather than at /welcome/.

This is because the app server will probably want to generate links to other views of its app, and will reinsert the "welcome": this becomes a pain, and means that all links on your pages will get HTTP redirects when visited (e.g. by search engines). There is no way that the proxying apache server can parse the HTML and tell when that "welcome" should be removed, so best to fix the server that's writing the links in the first place.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜