Pete Long
asked on
NGINX and Redirects
Hi,
I've spent a few weeks messing around with nginx to get to grips with it before I migrate my Wordpress site, (currently on Apache).
One thing can't work out is, In Apache I have a rewrite (in .htaccess) that redirects any request for
http://www.mysite.com/KB/Article/000001.htm
to
http://www.mysite.com/KB/Article/000001
It's because the site was originally written in flat html and theres thousands of links going to the old URLs.
In Apache this did the trick
-=-=-=-=-=-=-=-=-
RewriteEngine On
RewriteBase /
RewriteRule ^KB/Article/(.*).htm http://www.mysite.com/KB/Article/$1 [L]
-=-=-=-=-=-=-=-=-
How Do I do the same thing in nginx? I'm assuming I add the redirect to my
/etc/nginx/sites-enabled/d efault
File, as that the one the test site is using;
-=-=-=-=-=-=-=-
# Default server configuration
server {
listen 80 default_server;
listen [::]:80 default_server;
# Set The Root Directory for the Entire Website
root /var/www/html/;
# Add index.php to the list if you are using PHP
index index.html index.htm index.nginx-debian.html;
# Add The Server IP Address or FQDN
server_name 123.123.123.123;
# The following does the WorkPress Rewrites for the permalinks
location / {
index index.php index.html index.htm;
try_files $uri $uri/ /index.php?$args;
}
# pass PHP scripts to FastCGI server
location ~ \.php$ {
fastcgi_pass unix:/run/php/php7.0-fpm.s ock;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_scr ipt_name;
include fastcgi_params;
include snippets/fastcgi-php.conf;
}
}
-=-=-=-=-=-=-=-
A) What do I need to add to replicate that Apache/.htaccess redirect.
B) Is there anything you would recommend I add/remove from the above config file.
Thanks in advance
Pete
I've spent a few weeks messing around with nginx to get to grips with it before I migrate my Wordpress site, (currently on Apache).
One thing can't work out is, In Apache I have a rewrite (in .htaccess) that redirects any request for
http://www.mysite.com/KB/Article/000001.htm
to
http://www.mysite.com/KB/Article/000001
It's because the site was originally written in flat html and theres thousands of links going to the old URLs.
In Apache this did the trick
-=-=-=-=-=-=-=-=-
RewriteEngine On
RewriteBase /
RewriteRule ^KB/Article/(.*).htm http://www.mysite.com/KB/Article/$1 [L]
-=-=-=-=-=-=-=-=-
How Do I do the same thing in nginx? I'm assuming I add the redirect to my
/etc/nginx/sites-enabled/d
File, as that the one the test site is using;
-=-=-=-=-=-=-=-
# Default server configuration
server {
listen 80 default_server;
listen [::]:80 default_server;
# Set The Root Directory for the Entire Website
root /var/www/html/;
# Add index.php to the list if you are using PHP
index index.html index.htm index.nginx-debian.html;
# Add The Server IP Address or FQDN
server_name 123.123.123.123;
# The following does the WorkPress Rewrites for the permalinks
location / {
index index.php index.html index.htm;
try_files $uri $uri/ /index.php?$args;
}
# pass PHP scripts to FastCGI server
location ~ \.php$ {
fastcgi_pass unix:/run/php/php7.0-fpm.s
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_scr
include fastcgi_params;
include snippets/fastcgi-php.conf;
}
}
-=-=-=-=-=-=-=-
A) What do I need to add to replicate that Apache/.htaccess redirect.
B) Is there anything you would recommend I add/remove from the above config file.
Thanks in advance
Pete
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thanks for the following up, I've been offline for a while - trying now
P
P
ASKER
Same Result :( stops me getting to the main page also when I add that, I ge the welcome to nginx page instead.
Pete
Pete
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Yep thats the one!
:)
:)
ASKER
Found the solution myself
Open in new window