M
melkior_inactive
Guest
Ok, mod rewrite is very good function of Apache Web Server.
The potential is enormous. As you might or might not know, I'm developing a link selling app for UK WW.
And we want the app to be SEO friendly.
So this is a potential use of mod rewrite.
It's also good if you want to hide the structure of your website, and the arguments that you pass to the script.
So what does it look like?
Well this is the basic idea:
you have a site called www.domain.com
and you have a script which passes the arguments.
So your url look like this:
www.domain.com/index.php?query=xxx&id=yyy
mod rewrite enables you to change that into:
www.domain.com/xxx/yyy/
First of all make sure that mod_rewrite is available on your server and turned on.
You can check that out by creating a file (let's call it phpinfo.php) with the following content:
Go to that page and search for mod_rewrite. If you find it you're good to go.
If not, contact your host.
OK, now create a .htaccess file with this content:
Upload the file to your server into the folder that contains the script.
Now, what this does is: when someone requests bla/bla/ on your server, it automatically gets transcribed to index.php?query=bla&id=bla
Cool, isn't it?
But maybe you want your site to look like this:
www.domain.com/xxx-yyy.html
No problem!
This is the setup for the .htaccess file:
So if you need index.php?query=bla&id=bla you can now access it like bla-bla.html
Now, all you need to do is update the links in your site and your site is SEO friendly and harder to hack.
Here's a little help with that. If you have static links you have no problems, but chances are that your script is generating the urls based on various conditions.
So here's the old code:
You'd change it to:
for the first type of url rewrite.
Or:
for the second type.
Hope it helps.
The potential is enormous. As you might or might not know, I'm developing a link selling app for UK WW.
And we want the app to be SEO friendly.
So this is a potential use of mod rewrite.
It's also good if you want to hide the structure of your website, and the arguments that you pass to the script.
So what does it look like?
Well this is the basic idea:
you have a site called www.domain.com
and you have a script which passes the arguments.
So your url look like this:
www.domain.com/index.php?query=xxx&id=yyy
mod rewrite enables you to change that into:
www.domain.com/xxx/yyy/
First of all make sure that mod_rewrite is available on your server and turned on.
You can check that out by creating a file (let's call it phpinfo.php) with the following content:
PHP:
<? phpinfo(); ?>
Go to that page and search for mod_rewrite. If you find it you're good to go.
If not, contact your host.
OK, now create a .htaccess file with this content:
Code:
Options +FollowSymLinks
RewriteEngine On
RewriteRule ^(.*)/(.*)/$ index.php?query=$1&id=$2 [L]
Now, what this does is: when someone requests bla/bla/ on your server, it automatically gets transcribed to index.php?query=bla&id=bla
Cool, isn't it?
But maybe you want your site to look like this:
www.domain.com/xxx-yyy.html
No problem!
This is the setup for the .htaccess file:
Code:
Options +FollowSymLinks
RewriteEngine On
RewriteRule ^(.*)-(.*).html$ index.php?q=$1&id=$2 [L]
Now, all you need to do is update the links in your site and your site is SEO friendly and harder to hack.
Here's a little help with that. If you have static links you have no problems, but chances are that your script is generating the urls based on various conditions.
So here's the old code:
PHP:
<html>
<body>
...
...
<?
echo '<a href="$siteurl/index.php?query=type&id=$id">Link</a>';
?>
PHP:
<html>
<body>
...
...
<?
echo '<a href="$siteurl/type/$id/">Link</a>';
?>
Or:
PHP:
<html>
<body>
...
...
<?
echo '<a href="$siteurl/type-$id.html">Link</a>';
?>
Hope it helps.