Php

How To Enable mod_rewrite In Nginx

This tutorial help to enable mod_rewrite in nginx server.The .htaccess is not supported by Nginx server, So will implement URL routing into nginx using site virtual host file. The URL Rewrite use to make URLs Search Engine Friendly.

The mod_rewrite module normally uses a rule-based rewriting engine to rewrite requested URLs based on PCRE regular-expression parser. By defaults mod_rewrite maps a URL to a filesystem path. It allows you to rewrite URL based on server variables, environment variables, HTTP headers, or time stamps.

The Apache server is supporting .htaccess file. I have already shared How To Enable Mod_Rewrite Module In Apache

Nginx Mod_Rewrite URL Example

I am assuming you have CentOS machine and Nginx is installed on it. There are following steps will follow to implement URL rewrite rules –

Step 1: I am assuming you’re using the default.conf file. We will open this file which is stored in /etc/nginx/conf.d/ folder –

Step 2: Search the below code into the virtual host file(default.conf).

Related Post
location / {
        root   /usr/share/nginx/html;
        index  index.html index.htm;
    }

We will make following changes into the above line and save the file –

location / {
        root   /usr/share/nginx/html;
        index  index.html index.htm;
        try_files $uri $uri/ /index.php?$args;
    }

Step 3: We will reload Nginx server service using below command –
sudo service nginx reload

How To Enable Mod_Rewrite for Subfolder

Normally, web hosting provider install WordPress site into the sub folder(phpflow) then , We need to change location block as like below –

from –

location / {
index index.php index.html index.htm;
try_files $uri $uri/ /index.php?$args;
}

replace To –

location /phpflow/ {
try_files $uri $uri/ /wordpress/index.php?$args;
}

You need to restart nginx service or server.

Recent Posts

Configure and Retrieve S3 Information Using Laravel PHP-AWS-SDK

This tutorial helps integrate a PHP SDK with Laravel. We'll install aws-php-sdk into laravel application and access all aws services… Read More

2 months ago

What is the Purpose of php_eol in PHP?

in this quick PHP tutorial, We'll discuss php_eol with examples. PHP_EOL is a predefined constant in PHP and represents an… Read More

8 months ago

Laravel Table Relationship Methods With Example

This Laravel tutorial helps to understand table Relationships using Elequonte ORM. We'll explore laravel table Relationships usage and best practices… Read More

8 months ago

Exploring the Power of Laravel Eloquent Join?

We'll explore different join methods of Laravel eloquent with examples. The join helps to fetch the data from multiple database… Read More

9 months ago

Quick and Easy Installation of Laravel Valet

in this Laravel tutorial, We'll explore valet, which is a development environment for macOS minimalists. It's a lightweight Laravel development… Read More

9 months ago

What is Laravel Soft Delete and How Does it Work?

I'll go through how to use soft delete in Laravel 10 in this post. The soft deletes are a method… Read More

9 months ago

Categories