Welcome! Log In Create A New Profile

Advanced

Conditional Rewrite from .htaccess

Posted by Bill-nginx 
Conditional Rewrite from .htaccess
May 08, 2012 12:17AM
This is what im tying to re write for nginx...

If i browse to www.domain.com/anything/anything/anything/ the address in the browser shows www.domain.com/anything/anything/anything/ but the file that is loaded is index.php
If i browse to www.domain.com/blah/blah/blah/blah/ the address in the browser shows www.domain.com//blah/blah/blah/blah/ but the file that is loaded is index.php

but

If i browse to www.domain.com/html/test.html the address in the browser shows www.domain.com/html/test.html and the file that is loaded is test.html
If i browse to www.domain.com/css/default.css the address in the browser shows www.domain.com/css/default.css and the file that is loaded is default.css
If i browse to www.domain.com/images/logo.png the address in the browser shows www.domain.com/images/logo.png and the file that is loaded is logo.png
If i browse to www.domain.com/php/footer.php the address in the browser shows www.domain.com/php/footer.php and the file that is loaded is footer.php

So here is the .htaccess contents form the apache server

RewriteEngine on
RewriteRule ^html [L,NC]
RewriteRule ^css [L,NC]
RewriteRule ^images [L,NC]
RewriteRule ^php [L,NC]
RewriteRule ^.*$ index.php [L,QSA]

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_URI} !directory/(.*)$
RewriteCond %{REQUEST_URI} !(.*)$
RewriteRule ^(.*)$ http://www.domain.com/$1 [R=301,L]

I've tried many times to understand how to re-write this for nginx, but I just cant get a grip on how to achieve this, any help is most appreciated
Re: Conditional Rewrite from .htaccess
May 08, 2012 01:33AM
So far I have the below and the requests for the html, css, images and php files are working great.

But when i make a request for www.domain.com/blah/blah/blah/ im getting a 404, what i really want is for the URL to reamin as www.domain.com/blah/blah/blah/ but load the index.php file

location ~ directory/(.*)$ {
}

location ~ (.*)$ {
}

location /html {
rewrite ^/html / break;
}

location /css {
rewrite ^/css / break;
}

location /images {
rewrite ^/images / break;
}

location /php {
rewrite ^/php / break;
}

location / {
rewrite ^(.*)$ /index.php break;
if (!-e $request_filename){
rewrite ^(.*)$ http://www.domain.com/$1 redirect;
}
}
Sorry, only registered users may post in this forum.

Click here to login

Online Users

Guests: 294
Record Number of Users: 8 on April 13, 2023
Record Number of Guests: 421 on December 02, 2018
Powered by nginx      Powered by FreeBSD      PHP Powered      Powered by MariaDB      ipv6 ready