htaccess to nginx rules - .htaccess

I have a .htaccess file that I'm having trouble converting.
content of the .htaccess file:
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_URI} ^system.*
RewriteRule ^(.*)$ /index.php/$1 [L]
#request to index.php
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
#This last condition enables access to the images and other folders,
RewriteCond $1 !^(index\.php|login|images|img|js|css|public|data|simplepie|application|system|cache)
RewriteRule ^(.*)$ index.php/$1 [L]
Nginx:
location / {
try_files $uri $uri/ index.php$is_args$args;
rewrite ^system.* index.php/$1 break;
if (!-e $request_filename){
rewrite !^(index\\.php|login|images|img|js|css|public|data|simplepie|application|system|cache) index.php/$1 break;
}
Any help will be appreciated.
Thanks

Related

use htaccess to stop processing request for favicon

i have two htaccess files, one for the root folder and another for the public folder. my problem is i'm getting an error because request for the favicon.ico is been processed. how do i stop the processing of the favicon?
below is my .htaccess files
:root folder
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond ^([^/]+)/?$ !^favicon\.ico
# Stop processing if already in the /public directory
RewriteRule ^public/ - [L]
# Static resources if they exist
RewriteCond %{DOCUMENT_ROOT}/public/$1 -f
RewriteRule (.+) public/$1 [L]
# Route all other requests
RewriteRule (.*) public/index.php?request=$1 [L,QSA]
</IfModule>
:public folder
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond ^([^/]+)/?$ !^favicon\.ico
RewriteCond %{REQUEST_URI} !^/images/
RewriteCond %{REQUEST_URI} !^/javascripts/
RewriteCond %{REQUEST_URI} !^/stylesheets/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?request=$1 [NC,L]
</IfModule>
the public folder is in the root folder

WordPress in Laravel public folder returns 404 not found

I've a laravel installed in /dev.domain.com/ and RootDocument is set to /dev.domain.com/public
The laravel works without any problem and then I install WordPress in newly created directory named "blog" under the laravel's public folder
Wordpress path : /dev.domain.com/public/blog
On localhost I'm can access /blog and setup wordpress as usual, however the problem come with I deploy to live server by cloning with git. The laravel path works fine but when I try to access /blog directory in public folder it returns 404 Not found
Below is the Laravel
/dev.domain.com/public/.htacess
<IfModule mod_rewrite.c>
<IfModule mod_negotiation.c>
Options -MultiViews
</IfModule>
RewriteEngine On
# Redirect non ssl to ssl
# and don't redirect subdomain
RewriteCond %{HTTP_HOST} ^dev\.domain\.com [NC]
RewriteRule ^(.*) - [L]
RewriteCond %{HTTP_HOST} ^domain\.com [NC]
RewriteRule ^(.*) http://www.domain.com/$1 [L,R=301]
RewriteCond %{HTTPS} off
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L,NE]
# Redirect Trailing Slashes If Not A Folder...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)/$ /$1 [L,R=301]
# Handle Front Controller...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
</IfModule>
and Wordpress
/dev.domain.com/public/blog/.htaccess
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /blog/
# Disable WordPress front-end
RewriteCond %{REQUEST_URI} !/wp-admin
RewriteCond %{REQUEST_URI} !/wp-includes
RewriteCond %{REQUEST_URI} !/wp-login\.php$
RewriteCond %{REQUEST_URI} !/wp-content
RewriteRule (.*) https://www.domain.com/ [R=301,L]
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress
I've tried to add this one but no chance to make it works
RewriteCond %{REQUEST_URI} !^/blog
Above
RewriteRule (.*) https://www.domain.com/ [R=301,L]
Try this recipe, it works for me.
Add to Laravel .htaccess:
RewriteCond %{REQUEST_URI} !^/blog/ #
And change these lines in Wordpress .htaccess:
RewriteBase /blog/
RewriteRule . /blog/index.php [L]

Htaccess RewriteRule change subdomain url

I'm in this situation
http://example.com/sub-domain/
and I wish to have this
http://example.com/sub/domain/
without loosing in SEO, what's the right RewriteRule?
At the moment this is my .htaccess file in the subdomain DOCUMENT_ROOT
Options -Indexes +FollowSymLinks
RewriteEngine On
RewriteBase /sub-domain/
# exclude any paths that are not codeigniter-app related
RewriteCond %{REQUEST_URI} !^/server-status
RewriteCond %{REQUEST_URI} !^/server-info
RewriteCond %{REQUEST_URI} !^/docs
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
<IfModule mod_php5.c>
RewriteRule ^(.*)$ index.php/$1 [L]
</IfModule>
# the following is for rewritting under FastCGI
<IfModule !mod_php5.c>
RewriteRule ^(.*)$ index.php?/$1 [L]
</IfModule>
EDIT
In my root domain I have installed Wordpress and this is the .htaccess
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{ENV:REDIRECT_STATUS} 200
RewriteRule .* - [L]
RewriteBase /
RewriteRule ^index\.php$ - [L]
# add a trailing slash to /wp-admin
RewriteRule ^([_0-9a-zA-Z-]+/)?wp-admin$ $1wp-admin/ [R=301,L]
RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^ - [L]
RewriteRule ^([_0-9a-zA-Z-]+/)?(wp-(content|admin|includes).*) $2 [L]
RewriteRule ^([_0-9a-zA-Z-]+/)?(.*\.php)$ $2 [L]
RewriteRule . index.php [QSA,L]
</IfModule>
Leave /sub-domain/.htaccess as is. And have this rule in root .htaccess (a level above /sub-domain/):
RewriteEngine On
RewriteCond %{THE_REQUEST} /sub-domain(\S*)\s [NC]
RewriteRule ^ /sub/domain%1? [R=301,L,NE]
RewriteRule ^sub/domain(/.*)?$ sub-domain$1 [L,NC]

Convert .htaccess to Nginx

I have rewrite .htaccess like that
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{HTTP_HOST} ^www\.(.*)$ [NC]
RewriteRule ^(.*)$ http://%1/$1 [R=301,L]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ index.php/$1 [QSA,L]
</IfModule>
i try to convert in NGINX rewrite
but not success
# nginx configuration location / { rewrite ^(.*)$ http://%1/$1 redirect; if (!-e $request_filename){ rewrite ^(.*)$ /index.php/$1 break; } }
anyone can help me ?

htaccess to nginx converter

My htaccess code:
RewriteBase /mysite/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} (/[^.]*|\.)$ [NC]
RewriteRule .* index.php [L]
In nginx config I've tried this but it didn't work
location /mysite{
try_files $uri $uri/ /mysite/index.php$is_args$args;
}
Anyone can help me, tks so much.
p/s: I've tried http://www.anilcetin.com/convert-apache-htaccess-to-nginx/ and http://winginx.com/htaccess, but both of them can't help

Resources