So, what is mod_rewrite for? - Printable Version +- Webnetics UK Ltd. - Forums (https://www.webneticsuk.com/forum) +-- Forum: News & Announcements (https://www.webneticsuk.com/forum/forumdisplay.php?fid=2) +--- Forum: VWDesigns Blog (https://www.webneticsuk.com/forum/forumdisplay.php?fid=12) +---- Forum: Server (https://www.webneticsuk.com/forum/forumdisplay.php?fid=18) +---- Thread: So, what is mod_rewrite for? (/showthread.php?tid=16) |
So, what is mod_rewrite for? - webnetics - 04-12-07 Simply, mod_rewrite is used for rewriting a URL at the server level, giving the user output for that final page. So, for example, a user may ask for http://www. Your site .com/page1 but will really be given http://www your site .com/page1.php?colour=blue by the server. Of course, the user will be none the wiser to this little bit of chicanery. We currently use mod_rewrite on a lot of our software at Virtual Web Designs, and we always give the user the chose to turn this on / off. What do I need to get mod_rewrite working? There’s pretty much only one thing you’ll need to get mod_rewrite working for you, and that’s to have the mod_rewrite module installed on your Apache server! I’m going to assume that you don’t have access to view or edit the Apache server httpd.conf file, so the easiest way to check whether the mod_rewrite module is installed will be to look on your phpinfo page. If you’ve not already created one of these for yourself, just copy and paste the following code into an new text file using your favourite text editor, save it as phpinfo.php, and upload it to your server: <?php phpinfo(); ?> Load that page up in your web browser, and perform a search for “mod_rewriteâ€. All being well, you’ll find it in the “Apache loaded modules†section of the page. If it isn’t there, you’ll have to contact your hosting company and politely ask them to add it to the Apache configuration. Assuming the mod_rewrite module is loaded, then you’re good to go! Example mod_rewrite This isn’t going to be anything fancy; we’re just going to redirect people who ask for wdesigns.htm to the page vrscripts.htm instead. <html> <head> <title>vwdesigns webpage</title> </head> <body> <p> This is vwdesigns webpage </p> </body> </html> We’re going to add a couple of lines to your .htaccess file. The .htaccess file is a text file which contains Apache directives. Any directives which you place in it will apply to the directory which the .htaccess file sits in, and any below it. To ours, we’re going to add the following: RewriteEngine on RewriteRule ^indexl.html$ vwdesigns.htm Upload this .htaccess file to the same directory as vwdesigns.htm and index.htm, and reload vwdesigns page. You should see index page being displayed, but vwdesigns URL. If you still see vwdesigns page being displayed, then check you’ve followed the instructions correctly (you may have to clear your cache). |