NGINX rewrite rules help. Redirect not working and want to get rid of index.php in urls
- by Tamerax
hey!
I have 2 questions for nginx users.
1) I'm trying to setup my joomla server onto my new linode running NGINX and after much (like days) of searching and testing, I finally have a config that works with with SEF url plugins...sorta. I was using an apache system on the old server and it used mod_rewrite and life was fine in terms of SEF. Since NGINX doesn't have mod_rewrite, I found something that works BUT it constantly leaves index.php in the urls.
ex: http://mysite.com/index.php/forum
i want it to be just http://mysite.com/forum but without mod_rewrite it doesn't seem to be possible in joomla that i'm aware of. I know in wordpress it IS possible but I have to use a plugin.
Here is my config file:
server {
listen 80;
server_name mysite.com www.mysite.com;
access_log /home/public_html/mysite.com/log/access.log;
error_log /home/public_html/mysite.com/log/error.log;
root /home/public_html/mysite.com/public/;
large_client_header_buffers 4 8k; # prevent some 400 errors
index index.php index.html;
fastcgi_index index.php;
location / {
expires 30d;
error_page 404 = @joomla;
log_not_found off;
}
# Rewrite
location @joomla {
rewrite ^(.*)$ /index.php?q=last;
}
# Static Files
location ~* ^.+.(jpg|jpeg|gif|css|png|js|ico)$ {
access_log off;
expires 30d;
}
# PHP
location ~ \.php {
keepalive_timeout 0;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
include /usr/local/nginx/conf/fastcgi_params;
fastcgi_param SCRIPT_FILENAME /home/public_html/mysite.com/public /$fastcgi_script_name;
}
}
2) second question should be easy but i can't get it to work.
I want to use the same config I posted above and have either mysite.com or www.mysite.com both forward to mysite.com/portal.
Basically when you hit up the front page with or without the www, it all gets forwarded to a sub directory on the server I called Portal.
I have tried several variations of:
rewrite ^/(.*) http://www.example.com/portal/$1 permanent;
but it usually ends with firefox telling me there is some crazy loop happening the address bar saying something like mysite.com/portalportalportalportalportal.........on and on.
So, any help on either of these issues would be awesome!!
Thanks!!