I'm trying to move a site that was born on apache server to a nginx server.
I've the current .htaccess:
RewriteEngine on
RewriteRule ^(Personal)($|/) - [L]
RewriteRule ^mng/([-0-9a-zA-Z/%&]+)$ /index.php?aurl=$1 [L]
RewriteRule ^([-0-9a-zA-Z/%&]+)$ /index.php?url=$1 [L]
An online converter has converted these rules into:
location /mng {
rewrite ^/mng/([-0-9a-zA-Z/%&]+)$ /index.php?aurl=$1 break;
}
location / {
rewrite ^/([-0-9a-zA-Z/%&]+)$ /index.php?url=$1 break;
}
I added them to my nginx configuration but does not work, where am I wrong?
When I visit a page domain.ex/mng/index I can download the page..
This is my complete nginx conf:
server {
listen 80;
listen [::]:80;
root /var/www;
index index.php index.html;
server_name domain.ex;
location / {
rewrite ^/([-0-9a-zA-Z/%&]+)$ /index.php?url=$1 break;
}
location /mng {
rewrite ^/mng/([-0-9a-zA-Z/%&]+)$ /index.php?aurl=$1 break;
}
location ~ \.php$ {
include snippets/fastcgi-php.conf;
fastcgi_pass unix:/run/php/php7.0-fpm.sock;
}
}
After several attempts, I solved the problem with the following rules:
location /mng/ {
rewrite ^/(.*)/(.*)$ /?aurl=$1;
}
location / {
rewrite ^/(.*)/(.*)$ /?url=$1;
}
Related
I have set up the existing Yii2 advanced project in Apache server. before it was on nginx server. I have a nginx.conf file. that I want to convert it .htaccess file to make a project working on Apache server as well.
Here is the nginx.conf file code
location / {
index index.php index.html;
try_files $uri $uri/ /index.php?$args;
} # / location
location /html {
alias /../../html/;
}
location /api {
if ( !-e $request_filename ) {
rewrite ^/api/(.*)$ /api/index.php?$1 last;
}
}
location /dten {
if ( !-e $request_filename ) {
rewrite ^/dten/(.*)$ /dten/index.php?$1 last;
}
}
location /dten-backend {
if ( !-e $request_filename ) {
rewrite ^/dten-backend/(.*)$ /dten-backend/index.php?$1 last;
}
}
location /dten-crm {
if ( !-e $request_filename ) {
rewrite ^/dten-crm/(.*)$ /dten-crm/index.php?$1 last;
}
}
I tried this, but it is not working.
# if a directory or a file exists, use it directly
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
# otherwise forward it to index.php
RewriteRule / index.php
# Handle the case of backend, skip ([S=1]) the following rule, if current matcheds
RewriteRule ^/dten-backend(/(.*))?$ /dten-backend/$2 [S=1]
So I've been using apache for all of my PHP projects, but now I've been forced to using nginx on the server. I've no clue how to do pretty urls with nginx. So I started converting my .htaccess file into an nginx config script, and tried modifying the nginx config file, but no luck.
This is my .htaccess file:
Options -MultiViews
RewriteEngine On
RewriteBase /wallfly-mvc/public
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.+)$ index.php?url=$1 [QSA,L]
This is my nginx.conf server block:
server {
listen 80; listen [::]:80;
server_name deco3801-superflyz.uqcloud.net;
root /var/www/htdocs;
include "set_cookie.conf";
rewrite_by_lua_file "etc/nginx/lua/auth_filter.lua";
location / {
index index.html index.htm index.php index.jsp index.aspx;
try_files $uri $uri/ =404;
}
location /wallfly-mvc/public/ {
if (!-e $request_filename) {
rewrite ^/wallfly-mvc/public/(.+)$ /wallfly-mvc/public/index.php?url=$1 break;
}
}
}
I want every request to point to public/index.php. This is my project structure:
wallfly-mvc/
app/
public/
index.php
css/
js/
img/
How should I change the nginx.conf file? Any help would be appreciated.
You can use location ^~ to capture the directory. Its priority is higher location /
server {
#...
location ^~ /wallfly-mvc/public/ {
if (!-e $request_filename) {
rewrite ^/wallfly-mvc/public/(.+)$ /wallfly-mvc/public/index.php?url=$1 break;
}
}
}
One server same source code Magento Enterprise , if i run it in Apache after post request one Get request received , but in nginx not work , and shows me page not found 404.
I check it using firebug in Firefox .
URL : /customer/account/create/
After click Subbmit it redirect to
URL : /customer/account/index/ = and user longed page come
But in Nginx
URL : /customer/account/create/
After click Subbmit it redirect to
http://52.88.205.17/customer/account/createpost/ = 404 page not found
Apache Server default configuration and htaccess is
Options +FollowSymLinks
RewriteEngine on
RewriteRule ^api/rest api.php?type=rest [QSA,L]
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
RewriteCond %{REQUEST_METHOD} ^TRAC[EK]
RewriteRule .* - [L,R=405]
RewriteCond %{REQUEST_URI} !^/(media|skin|js)/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-l
RewriteRule .* index.php [L]
And Nginx Configuration is
server {
listen 80;
server_name http://52.88.205.17;
location / {
root /var/www/html/src/;
index index.php;
try_files $uri $uri/ #handler;
}
location #handler { ## Magento uses a common front handler
rewrite / /index.php;
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /var/www/html/src/;
}
#location /index.php/admin { deny all;}
#Disable .htaccess and Hidden Files
location /. { return 404; }
location ~ .php/ { ## Forward paths like /js/index.php/x.js to relevant handler
rewrite ^(.*.php)/ $1 last; }
location ~ \.php$ {
root /var/www/html/src/;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
I solved this problem Increasing PHP Buffer Size
fastcgi_buffers 16 16k;
fastcgi_buffer_size 32k;
well I have this mod_rewrite in my old apache configuration (htaccess) and I am trying to set up the configuration to nginx, but I can not really understand how it really works in nginx, I'm a newbie in all this nginx stuff, could anyone help me to translate this... Thank you so much in advance.
Current htacces file:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_URI} !^(/static/)
RewriteRule . /app.php [L]
</IfModule>
Virtual config file test.url:
server {
server_name test.url;
access_log /var/www/test.url/logs/access.log;
error_log /var/www/test.url/logs/error.log;
root /var/www/test.url/public_html/blank;
location / {
app.php;
}
location ~ \.php$ {
include /etc/nginx/fastcgi_params;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME /var/www/test.url/public_html/$
}
}
Instead of:
location / {
app.php;
}
Try:
location /static/ {
# do nothing, we don't want to rewrite /static/
}
location / {
try_files $uri $uri/ /app.php
}
I am trying to convert the code from the htaccess to Nginx but without any success, and yes i have tried all the online converter but it did not help, so can any here on stockoverflow help me please? I'm going crazy soon :-p (Here is the code from the htaccess)
RewriteCond %{HTTP_HOST} ^www.WEBSITE.com
RewriteRule (.*) http://WEBSITE.com/$1 [R=301,L]
RewriteCond %{request_filename} -f
RewriteRule ^(.*) $1 [L]
RewriteRule ^([a-z]+)(/([^/]{0,32})(/.+)?)?$ index.php?a=$1&q=$3 [L]
Please try the following:
server {
listen 80;
server_name www.website.com;
return 301 $scheme://website.com;
}
server {
listen 80;
server_name website.com;
root /path/to/root;
location / {
try_files $uri #rewrite;
}
location #rewrite {
rewrite ^/([a-z]+)/?([0-9a-zA-Z]*)/?.*$ /index.php?a=$1&q=$2 last;
}
}