• Home
  • WP tuts
  • Hosting talk
    • Free hosting
    • Cheap Hosting
    • comparison cloud , vps, shared, wordpress
    • managed wordpress hosting
    • managed cloud hosting
  • Speed up wordpress
  • Pc world
  • Services
  • About Me

RAaz Kumar .com

wordpress tutorials seo hosting etc

nginx rewrite rules with examples 301 redirection

htaccess rewrite rules easy to generate, but nginx as new thing from ,2004,  many people struggles at beginning.

Nginx 301 reduction rewrite rule

nginx old url to new url
generally we use wordpress plugins like redirect.
sub directory to parent directory redirection

nginx non www to www redirection

server {    listen      80;    server_name example.org;    return      301 http://www.example.org$request_uri;}
server {    listen      80;    server_name www.example.org;    # …}
One server block for redirection.
other sever block for application

rewrite vs return vs try_files

try files directive
directs the application server
nginx checks directories and file
and returns the $uri.(current uri request)(URI stands for Uniform Resource Identifier)
try files based  on files index.php, index.html etc
try file $uri $uri/
if user requested web.com/text
then nginx looks text if not text/

Return

return just a simple form less programming scope less memory intensive
if pattern find just return this page.
useful to redirect old domain to new, old url to new.
server { listen 80;
server_name www.old-name.com;
return 301 $scheme://www.new-name.com$request_uri;
}
or
server{
root /var/www/html/oldsite
servername old.com
location\ {
return 301 http://google.com/$1
}
}
return 403 “service unavailable”
or
return 403;
return 3x, 1x,5x,4x codes
rewrite only 301, 302
return useful when it matches the server or location block.
for url forwardings

nginx rewrite module

when you use regex use this.
rewrite regex URL (flag);
regex (nginx has process before it’s going for server block)
nginx rewrite module,
1st process regex, and look for directives like break,last, permanent,if,return,set
flags, rewrite etc
permanent =301
last; tells nginx to stop current block and search new block(server, location)
break=
Wildcard redirection in nginx
converting htaccess rules to nginx rewrite rules
nginx variables
$scheme protocol http or https
$request_uri  full uri including arguments
The $1 and $2 variables capture the path elements that aren’t changing.
$request_uri vs $1 variables
set $someword $1 ;
custom variable ($1) that in fact is equivalent to the built‑in $request_uri variable

Nginx regex modifiers

location =/test
not applies to site.com/test/tdd/
no modifier
location /test
applies to site.com/test/,
~ operator
case-sensitive match
location ~ ^/test$
^ starts with ,
$ ends with
not applies to /TEST
~* operator (case insensitive)
location ~* ^/abcd$
applies to /TEST
^~ modifier
string should be match at beginning if the requested uri
starts with specific & case sensitive
~ or ~*  requested uri & location block should be match
location ~* ^/document$ {
[…] # requests exactly matching “/document”
location ~* /myapp/.+\.php$ { #… }
asterisk after the tilde (~*) makes the match case insensitive.
URI ending with myapp/file.php, such as /test/myapp/hello.php and /myapp/hello.php.
case‑insensitive test of the regex (.*myapp)/(.+\.php)$ against the URI /myapp/hello.php:
location ~* (.*/myapp)/(.+\.php)$ {    #…}
understanding nginx regex operators
^ matches starts with
$ matches empty string at the end
~
(.*)regex group
.* matches all
\* matches everything after \
?
rewrite ^/(.*)\.(png|jpg|gif)$
startswith/anystringgouped&endswith.(png|jpg|gif.
~^(www)\.example\.com$; # $1 = www
amp to non amp conversion
location

Related topics:

  1. enable browser caching in wordpress apache nginx caching headers explained
  2. nginx fastcgi cache wordpress how to configure
  3. how to enable KeepAlive connections in apache nginx wordpress
  4. 301 & 302 Redirection in nginx, Htacess, wordpress etc Redirect URL & Domain SEO Friendly
  5. Top 10 most used Cat commands with examples (create, view, append files)




tutorials

  • Android Studio tutorials syllabus Topics Course details #AndroidApplicationDevelopment
  • xampp tutorials 2021 installation errors fix wordpress phpmyadmin mysql apache
  • Devops Syllabus topics PDF
  • CCNA Syllabus pdf (CCNA / CCNP vs devops vs mcsa /MCSE)
  • how to create a website free of cost on google
  • what is vpn vs proxy vs tor, http vs https, http2, tcp vs udp, kali linux sql source code injection
  • nginx server tutorials (installation, configuration, performance tuning, security)
    • nginx modules list (enable, disable, upgrade, install dynamic module)
    • monitor nginx request with nginx status amplify datadog new relic
    • nginx installation on ubuntu 20.04 LTS
    • Redis performance metrics & tuning for nginx apache ubuntu & debian
    • enable brotli compression nginx brotli vs gzip
    • nginx performance tuning
    • Top 10 tips to improve nginx server security
    • letsencrypt install configure on ubuntu / debian nginx
    • what is TTFB & how to Reduce it (server response time) Google pagespeed
    • enable php fpm status page, monitor & understand the report to tweak performance
    • 2021 php fpm pool manager configuration settings based on server spike
    • Letsencrypt SSL Installation on apache/Nginx ubuntu / debian
    • nginx rewrite rules with examples 301 redirection
    • use nginx as reverse proxy and load balancer for apache wordpress
    • nginx conf explained best config file performance tuning nginx.conf
    • nginx errors (504,502, 413, unable to start, syntax errors)
    • Pagespeed module install, configure, monitor, errors ft nginx &apache
    • Apache vs nginx (connection handling, modules, memory usage)
    • install lemp Linux, Nginx 1.15.12, MySQL 8, PHP fpm 7.3 on Ubuntu 18.04
    • nginx fastcgi cache wordpress how to configure
    • Redis / memcached installation on ubuntu 20.04 with wordpress mysql configuration
    • cloudflare timeout error 522 524 fix by increasing limit
  • Vivek Bindra Videos Transcription (business strategy)
  • AUdio Editing Background Noise removal (Audacity, Adobe Premiere Addition, Camtasia Filmora Windows Obs)
  • MySQL Tutorial (create,connect database, update tables, export etc) Documentation & TIPS
  • [INTRO] Ethical hacking / cyber Security / Penetration testing Tutorial -{updates frequently}
  • ubuntu tutorials installation download issues etc
  • Php tutorials
  • HTML & CSS Tutorials
  • Core Java Tutorial Free online
  • Linux sysadmin tutorials linux system administrator
  • apache server tutorial (install,config, performance tuning, security, error handling)

About

 

raaz kumar comI am Raaz Kumar, Most Of the time in a day , I Spend on WordPress, Hosting, Server related issues, So i decided write clean posts from my personal notes, so it will be useful for every one like me. Read More,,

Please Support my work by sharing, it can helps to create free content like this.

Twitter

Facebook

Youtube

 

PUBG Mobile Tips & Tricks

free fire how to play (a-z guide) guns, tips & tricks etc

Windows 10 tips & tricks

Pagespeed optimization

Pc building tips & tricks

nginx server tutorials

apache server tutorials

linux sysadmin tutorials

mysql Commands list pdf

Android studio tutorials

Gaming/ streaming tips

Airtel dth channel list

 

wordpress

 

Top 5  WP Google Analytics Plugins

WP Backup Plugins

Wp Comment Plugins

Top wordpress Security Plugins

WP Seo Plugins

WP Caching Plugins

Best Adsense Plugins for WordPress

Wp social Sharing Plugins

autoshare social media plugins

WP speed Optimization Plugins

Speedup WordPress google Score

More Wp tuts

Server Admin Cloud

 

Installing Nginx LEMP On ubuntu

Installing apache Lamp ubuntu

nginx fastcgi cache enable

php – fpm install  & Configuration

Opcache install & Configure

php -fpm pool manager explained

Mysql Install & Configuration

Redis Object cache install & configure

 

Nginx as Reverse Proxy and Load balancer

Load Balance / auto scaling in google cloud

Linux Commands PDF

Mysql Commands Pdf

Letsencrypt tutorial

mysqldump export & import 

Pagespeed Module install & configure

nginx.conf best file

mysql.conf best file

upgrade ubuntu

© 2021 - All Rights Reserved Disclaimer & Privacy Policy