Question

I have this site

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.

Was it helpful?

Solution

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';

OTHER TIPS

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top