Welcome Guest, Not a member yet? Register   Sign In
How can I add a port to a URL when accessing the /admin/ controller.
#1

[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.
#2

[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
#3

[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/".
#4

[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
}




Theme © iAndrew 2016 - Forum software by © MyBB