.htaccess maker

.htaccess generator maker easier

Htaccess Rewrite URLs Using Rewriterule , how to?

What is Rewrite URLs?

Some times you need to have a SEO URLs in your site, if your link structure is not SEO friendly like for example in WordPress default link structure www.htaccessmaker.com/?p=1 for posts or www.htaccessmaker.com/?cat=3 for categories, this links scheme is not SEO friendly because when you see www.htaccessmaker.com/?p=1 you will not know any thing about the content of this page, but suppose if you have a rewrited URL like www.htaccessmaker.com/htaccess-301-redirec/ by seeing this URL you will know that this page will talk about how to make 301 redirect using htaccess file.

How to make htaccess Rewrite URLs ?

A famous example about how we could force the redirect of the non www URLS to www URLS in a specific site, suppose we have the site name htaccessmaker.com, it will be like this:

RewriteCond %{HTTP_HOST}   !^www\.htaccessmaker\.com [NC] 
RewriteCond %{HTTP_HOST}   !^$ 
RewriteRule ^/(.*)         https://www.htaccessmaker.com/$1 [L,R]

Note that to use the Rewriterule you must do the following things first:

  1. Use the Tag <IfModule mod_rewrite.c> in the beginning of the rewrite code and  </IfModule> at the end.
  2. Start bu activating the RewriteEngine by setting it to on.
  3. Determine the RewriteBase for you rewrite, for example “/”.

A full example is to rewrite URLS for WordPress Blog:

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>

What is .htaccess Files

Htaccess File can be described as a configuration file that is used on web servers that are run by Apache Web server software. The htaccess file is normally placed in a directory and the directory is loaded on the Apache Web server. Once the htaccess is detected the Apache web server will execute it immediately.

Htaccess is also referred to as “Hypertext access” and it is a configuration file that simply controls the directly in which it is found. Htaccess also controls the sub-directories under the main directory it is found.

What can we do with Htaccess File:

  1. Make 301 redirect and other redirect types from one page to another.
  2. Rewrite your URLs to appear SEO friendly.
  3. Specify custom error pages for example for 404 error.
  4. Blocking users by using IP or by domain.
  5. Control folder listing when the visitor try to browse a real folder.
  6. Control the web browser caching.
  7. Adding MIME types.
  8. Folder password protection

This is the most common functions for it, there is many other uses.

301 redirect htaccess in simple way

Htaccess is a configuration file that contains some rules, therefore syntax errors such as missing letters can lead to inability to work correct and it may returns HTTP Error 500 Internal server error. Your first step towards the creation of 301 redirect through the use of htaccess file is to ensure that your FTP is configured to reveal all hidden files. The steps in making redirect using htaccess are:

  • Create an empty text with the use of a simple Windows text editor such as notepad, and save it as .htaccess without any name just the extension.
  • Add the redirect code below to the created file and save it.
  • Upload your created file to the root folder. If you are using a text editor, make sure the file is saved as a plain text. You can also save the file into other paths in case there are needs to.

Notes:

  1. If you have already the file on your server, download it and edit it using notepad, add the redirect code and then upload it again.
  2. To upload the file using FTP, you can use the free FTP client FileZilla, it is free and open source.
  3. You can use web file manager or editor like Cpanel file manager instead of FTP client.

The following code can do the desired 301 redirect for you:

Redirect 301 old_url  new_url

A real example about the 301 redirect is

Redirect 301 /about.htm http://www.clogica.com

In the above example we redirected the page about.htm to the new domain clogica.com

Your .htaccess File

Download Copy

You can create the .htaccess file using a good text editor like TextPad, UltraEdit and Microsoft WordPad. You cannot use Microsoft NotePad. An .htaccess file can contain a single or multiple lines depending upon the functions you want to include in it. You will need to use an FTP (File Transfer Protocol) program to upload the file. Also you must to upload the file in “ASCII” mode. Some FTP programs use “BINARY” as the default to upload files. If that’s the case you must change it to “ASCII”. Upload the file to the directory you want it to reside in. when you look at the files in your website’s directory you might not see it as your web server’s software is probably hiding it.

Redirect 301 old url to new url

Redirect 301 old domain to new domain

Enter full path for new domain

  • 1
  • 2
  • 3
  • 4
  • Next Page »

Copyright © 2021 · htaccessmaker.com · Log in