About Mod_Rewrite And How To Set Up / Enable In Apache Server

Share:

About Mod_Rewrite And How To Set Up / Enable In Apache Server. On this post, we learn about mod_rewrite. Mod_rewrite is one of the important modules owned by Apache. With this module, we can manipulate the URL as needed, such as changing the structure of the URL is too long to be shorter, making the preferred URLs by search engines, restructure dynamic URLs to flats link, preventing hot-linking, and so on.
About Mod_Rewrite And How To Set Up / Enable In Apache Server About Mod_Rewrite And How To Set Up / Enable In Apache Server

About Mod_Rewrite And How To Set Up / Enable In Apache Server

About Mod_Rewrite
As we have discussed in earlier paragraphs in this post, mod_rewrite has a very important role and even if a web hosting server does not enable mod_rewrite then a website will not be changed the structure. For example is, ​​dynamic url will remain that way so that search engines and humans will be difficult to memorize. This is a small example of not reactivation mod_rewrite in apache website hosting.

Function Of Mod_Rewrite and Writing
Here are some mod_rewrite function that we need to know. This set up might be beneficial to our website :
Mod_Rewrite For URL Rewrite
If you have a website link permalink unfavorable example: example.com/article.php?Id=14&cat=small-business and wish changed to example.com/article/small-business/title-post/. We can do this using mod_rewrite apache is in the website hosting server. For this topic, we will discuss it in detail the next post : Create SEO Friendly URLs Rewrite.
Mod_Rewrite For URL Redirect
In addition to URL rewrite, mod_rewrite usually often used to perform the redirect url. such as :
URL redirect from non-www to www

RewriteEngine on
RewriteBase /
RewriteCond %{HTTP_HOST} ^example.com [NC]
RewriteRule ^(.*)$ http://www.example.com$1 [L,R=301]

URL redirect from www to non-www

RewriteEngine on
RewriteBase /
RewriteCond %{HTTP_HOST} ^www.example.com [NC]
RewriteRule ^(.*)$ http://example.com/$1 [L,R=301,L]

We aim to redirect the above is to avoid duplicate content because the website www version and non-www search engines will be considered as two different websites.
Mod_Rewrite For Prevent Hotlinking
Mod_rewrite can be used to prevent other websites don’t use images that have been uploaded in our website hosting. The script is as follows :

RewriteCond %{HTTP_REFERER} !^$
RewriteCond %{HTTP_REFERER} !^http://(www\.)?example.com/ .*$ [NC]
RewriteRule \.(gif|jpg|swf|flv|png)$ /feed/ [R=302,L]

Benefits, website hosting that we use will not only lose a lot of bandwidth because often displays images shared on other websites. If the website hosting we have a large enough bandwidth or unlimited bandwidth, of course this is not a problem but if the our web hosting have limited bandwidth, surely the future could lead to unintended bad things like the emergence of a warning “Bandwidth Limit Exceeded” as a sign of bandwidth has been exhausted.
Mod_Rewrite For Block a Specific IP Address
If you want to block a visitor for certain reasons. You can do this automatically block using mod_rewrite. Script as follows :

RewriteCond %{REMOTE_ADDR} ^(A\.B\.C\.D)$
RewriteRule ^/* http://www.domain.com/block-page.php [L]

Replace the A\.B\.C\.D with the IP address you want to block. To find out the IP Address Location of each visitor, you can get information on Detect And Show IP Address Lookup.

Note: Save all this apache mod_rewrite scripts on .htaccess file.

How To Enable Mod_Rewrite In Apache Server

Mod_rewrite can work if this module should be enabled. Most web hosting has enabled mod_rewrite but there are web hosting is not enable, so it is necessary to set up the mod_rewrite.
First, locate the Apache folder.
For those of you who use a local server such as XAMPP, WAMP, PHPTriad and other servers is :
Go to Conf folder, then open the httpd.conf. Find this script,

#LoadModule rewrite_module modules/mod_rewrite.so

For those of you who use Apache on CentOS, follow the tutorial below :
Open httpd.conf in the directory /etc/httpd/conf/httpd.conf. Find the script below:

#LoadModule rewrite_module modules/mod_rewrite.so

Once you find a script that searched in the httpd.conf above then remove the # sign. Then look up the script :

AllowOverride None 

replace with :

AllowOverride all

Finish. Save httpd.conf and restart apache.

How To Check Enable Mod_Rewrite Using PHP
How to check weather mod_rewrite module is enabled or not ? Well there are lots of technique to check this but I’ll show you a very simple technique to check weather mod_rewrite module is enabled or not in your web server.
1. Create a php file, for example: info.php
2. Just type <? php phpinfo(); ?> in a php file.
3. Upload this file in your cpanel website hosting or in your localhost computer.
4. Open this file in web browser and just search the word mod_rewrite from the browser’s search menu. If it is found under the apache2handler section then this module is already loaded as you see in the picture below.
About Mod_Rewrite And How To Set Up / Enable In Apache Server About Mod_Rewrite And How To Set Up / Enable In Apache ServerHopefully this discussion can increase our knowledge.
Thanks for reading About Mod_Rewrite And How To Set Up / Enable In Apache Server

[Tutorial.World.Edu]

3 thoughts on “About Mod_Rewrite And How To Set Up / Enable In Apache Server

Leave a Reply

Your email address will not be published. Required fields are marked *