URL Rewriting allows a dynamic website to have clean and relevant URL addresses.
In the next article, we'll see what is URL rewriting for, and how to put it in function on your local apache server.
Normally, a URL address of a dynamic website would look like this :
But if we give the server a rewriting rule, it may look like this instead :
That's much cleaner, and easier to understand for the user and for Google. are a good way to improve SEO; moreover, Google doesn't like that much URLs that have more than two parameters into its query string (like in the first example).
If you wish to use URL rewriting « at home », you will probably need to activate the rewriting module (called mod_rewrite) of Apache. It is not very complex to do, but if you don't know how, it may be frustrating.
Then, here are solutions to set up URL Rewriting on your local server, using EasyPHP or Apache 2. Note that if you use MAMP or MAMP PRO, mod_rewrite is already enabled.
The only difference between the activation of mod_rewrite for EasyPHP 1.8 and for EasyPHP 2, is that in the version 2, there's only a line to uncomment.
Uncomment this line (remove #) in EasyPHP's configuration, httpd.conf (Menu e/Configuration/Apache in EasyPHP) :
Then, in the same configuration file, look for the <Directory> tag, relevant to your website. It should look like this :
You see « AllowOverride None »? Change it for « AllowOverride All ». This little trick will say to the server to pay attention to the .htaccess file. Without this modification, the .htaccess will be ignored by the server.
Uncomment the two following lines (remove #) in EasyPHP's configuration, httpd.conf (Menu e/Configuration/Apache in EasyPHP) :
In the same file, look for :
Take care that AllowOverride All is set to ALL and not set to NONE.
In EasyPHP 1.8, it's already set to ALL, but in EasyPHP 2.0, you must do it by hand. Be aware that if it's not set to ALL, the .htaccess file won't be considered by the apache server, it's very important (and very simple)!
It's very easy to do. Run the console (for Macs, it's called Terminal, and it's located in System applications) and type this :
Then, you must edit Apache's configuration, for that it doesn't ignore the .htaccess file. Open configuration file :
Find the tag <Directory> that is for your website, then search for AllowOverride None, and set it to AllowOverride All.
A default file may be there, in that case, its name would be 000-default.
Once you saved your changes, restart the server :
Very simple. Type :
in a PHP file, then check that « mod_write » is there. If it's not there, there's something wrong. Of course, it means that rewriting doesn't work. Take a look to previous steps again, you may have missed something.
Create your .htaccess file (the name of the file starts with a dot), and place it at the root of your site.
With Windows, it may cause a problem because this syntax is for hidden files (normally). It is possible to create the .htaccess file by using Notepad. Save your file this way : ".htaccess" (yes, with quotes).
You can also rename it in DOS, if you saved it in text format :
Insert these lines in the .htaccess file :
Create a file named page_test.html, also at the root of the website, with .htaccess.
Now that the rewriting rule is there, try to open essai.html in your browser.
Comments
Merci beaucoup !
Merci beaucoup !
thank you very much! This
thank you very much! This great job
Thanks a lot. It worked for
Thanks a lot. It worked for me.
Thanx man. This great job
Thanx man. This great job
Post new comment