CodeIgniter Forums
How can I add a port to a URL when accessing the /admin/ controller. - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20)
+--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23)
+--- Thread: How can I add a port to a URL when accessing the /admin/ controller. (/showthread.php?tid=48869)



How can I add a port to a URL when accessing the /admin/ controller. - El Forum - 01-31-2012

[eluser]jim-_-[/eluser]
I have a website that is cached with something called Varnish what this has done is make the Admin area very annoying to deal with as the caching disrupts login and so on, however if I add a specific port to the domain it will bypass Varnish.


What I can't figure out is how I can make CodeIgniter choose Domain.comTongueORT/admin when I go to the link Domain.com/admin, Now you say why don't you just write in TongueORT in the url you are going to, well if i do that when I press one link in the admin area the domain will be reset to Domain.com/admin/underArea . I'm gussing this should be possible to set up in routes.php , but I haven't figured it out yet.

TLBig GrinR; I want addresses under Domain.com/admin to go to the same domain but with a :port tagged onto the domain, to by pass caching.


PS: Its probably possible to but I don't want to do this in Varnish since I want all changes done in the PHP code.


How can I add a port to a URL when accessing the /admin/ controller. - El Forum - 01-31-2012

[eluser]meigwilym[/eluser]
If you have a MY_Admin_Controller (or similar) try this in the __construct().

Code:
$uri = parse_url($_SERVER['PATH_INFO']);

if(!isset($uri['port'] || $uri['port'] != 'PORT') header("Location:http://domain.com:PORT/admin", 301);

But check that the server provides PATH_INFO correctly first.

Mei


How can I add a port to a URL when accessing the /admin/ controller. - El Forum - 01-31-2012

[eluser]CroNiX[/eluser]
I'd create some new url helpers like: admin_url() and admin_anchor(). They just need to do an rtrim(base_url(), '/') to remove the slash from the original url and then append ":port/" to it, so your admin_url() would become:
http://yoursite.com:8088/
Then use those to generate your links.

OR, you could probably just do this with rewrite in .htaccess by detecting if the request string started with "admin/".


How can I add a port to a URL when accessing the /admin/ controller. - El Forum - 02-01-2012

[eluser]jim-_-[/eluser]
Thank you both, I was hoping for something like setting a .htaccess rule but in CI somehow (I r noob) so I wouldn't need to rewrite the the admin controller too much, also since things might change.

I'm going to read more about how to do it with .htaccess.

Edit for googlabillity: I found it was easier to do it in varnish after not finding any .htaccess script for my exact issue.

Code:
sub vcl_recv {
if (req.url ~ "admin") {
                 return (pipe);
         }
//Whatever else you need in it
}