Search Engine Friendly URL’s
A typical component of a website is a ‘latest main’ database. Individual main items would be accessed as:
http://www.myweb.com/main.php?id=20090729
(a call to the main.php script passing a single GET parameter which identifies which item to display)
Now we introduce the RewriteRule:
RewriteRule ^main/([0-9]+) /main.php?id=$1
Translation:
* IF the request starts with main/ followed by one or more digits;
* THEN call the main.php script with the id parameter set to those digits.
The URI then becomes:
http://www.myweb.com/main/20090729
Or, because we left the RHS of the regular expression open, we can also use:
http://www.myweb.com/main/20090729.html
There is a slight problem here in that, if Content Negotiation is enabled, this URI could be taken as a call to the main.php script with the rest of the URL (/20090729.html) being unused. This is because there is no file called /main/20090729.html, and no file called /main, but /main.php does exist and Content Negotiation is all about finding that out. In that situation the correct main item won’t be displayed.
The solution? We could re-name the script, change the format of the URI, or turn off Content Negotiation (which you might want to do in any case), but there’s a simpler option:
RewriteRule ^main/([0-9]+) /scripts/main.php?id=$1
By moving the script into a sub-directory, which we can do now because it’s no longer called ‘in place’, we avoid any chance of conflict. The /scripts/ directory can, and should, now be secured to avoid direct access.
One of the major benefits of using rewrite rules and ‘hiding’ the script is that ONLY requests matching the regular expression can access it. In this case it’s not possible for someone to pass a non-numeric parameter, and any attempt would result, rightly, in a 404 Not Found response.
An even better rule in this case could be:
RewriteRule ^main/([0-9]{8}) /scripts/main.php?id=$1
or, if you want to be really strict and enforce the .html extension:
RewriteRule ^main/([0-9]{8})\.html$ /scripts/main.php?id=$1
Thanks
Click Here To See A Similar Tutorial.
Incoming search terms:
- php script mod_rewrite url (3)
- download free php Scripts for Mod_rewrite (1)
- search engine friendly urls xampp (1)
- search engine friendly urls script (1)
- search engine friendly urls mod_rewrite _ (1)
- search engine friendly url using jsp (1)
- search engine friendly url script mod_rewrite php (1)
- script php sef url (1)
- rewriterule sharp minus (1)
- search friendly url using js (1)
- search my web search (1)
- using mod_rewrite with jsp (1)
- url friendly xammpp (1)
- tutorial SEF URL requests (1)
- tutorial rewriterule friendly (1)
- tutorial friendly url jsp (1)
- sef url tutorials (1)
- sef url script (1)
- sef url php script (1)
- Rewriterule sharp ajax (1)
- rewriterule secured to avoid direct (1)
- rewriterule search driendly URLS (1)
- friendly URL jsp (1)
- friendly url php download (1)
- how to disable back button on mouse in jsp (1)
- how to do page flipping with mod_rewrite (1)
- how to make search engine frendly url in jquery php mysql (1)
- how to make sef urls with mod rewrite (1)
- htaccess mod_rewrite tutorial search engine friendly links (1)
- mod_rewrite ajax url (1)
- mod_rewrite for jsp (1)
- mod_rewrite jsp (1)
- mod_rewrite php tutorial download (1)
- mod_rewrite to bypass symfony web folder (1)
- mod_rewrite tutorial mysql (1)
- php code in friendly url mod_rewrite (1)
- php sef freindly url script (1)
- rewriterul to 1 script (1)
- rewriterule for search engine friendly urls (1)
- xampp friendly url (1)
