I am writing a blog script for my site and would like it to have SE friendly URLs. I have never done this before and don't know where to start. Is there some moderately simple way of doing this. I know that phpArcadeScript uses a .htaccess file in the main directory to do this. I need to do this in perl/cgi.
This is the code I use for my directory script. You may find this useful Options +FollowSymLinks # Turn on the redirect engine RewriteEngine on # Check whether the domain name begins with either www or localhost # else redirect to www.yourdomain.com # Remove the following 2 lines if you donot want that to happen RewriteCond %{HTTP_HOST} !^(www|localhost) [NC] RewriteRule (.*) http://www.%{HTTP_HOST}%{REQUEST_URI} [R=301,NC,L] # yourdomain.com/path/to/dir/ will be rewritten to yourdomain.com/index.php?path=path/to/dir RewriteRule ^(.*)/$ index.php?path=$1 [QSA,L] # yourdomain.com/path/to/dir/page-{number}.html will be rewritten to yourdomain.com/index.php?path=path/to/dir&page={number} RewriteRule ^(.*)/([a-z0-9\-]+)([0-9]+).html$ index.php?page=$1&page=$3 [QSA,L] Code (markup):
I am usualy playing with $_SERVER["REDIRECT_URL"] I have a singel page site, then i redirect all 404 errors to a script error.php that decode what page they where trying to access with $_SERVER["REDIRECT_URL"], then i call a template file that display the page.
That's a good way of doing it, but don't forget to add a header('HTTP/1.1 200 OK'); on top of your script - otherwise Google and all other S.E. will think that those pages are missing (after all, Apache sends a 404 for them...)
But when the size and functions of the script increases, don't you think it is going to increase complexity? Also, I believe mod_rewrite will be much faster that that. What script is it?
Thanks everyone. I actually already got an answer on forum.modrewrite.com. But thanks for helping anyways.
Try below link! it will help you generate .htaccess http://www.webmaster-toolkit.com/mod_rewrite-rewriterule-generator.shtml
Since people are still posting here I might as well ask some more questions here. And thanks ColdMoney but it isn't working right for me. This is the code I have so far: Options +FollowSymLinks RewriteEngine On RewriteRule ^(.*)\.html$ index.shtml?action=$1 RewriteRule archives/(.*)-(.*)\.html$ index.shtml?action=showarchive&month=$1&year=$2 RewriteRule topics/(.*)\.html$ index.shtml?action=showtopic&id=$1 RewriteCond RewriteRule ^([^/]+)/([0-9]+)/([^/]+)\.html$ index.shtml?action=$1&id=$2&title=$3 [L] Code (markup): I want to add a condition that replaces any spaces or %20's in $3 with a dash (-). If that is possible. Otherwise I will have to edit the code in my .cgi files. Also when all is working will relative links work. Example: If the user is at mydomain.com/blog/posts/1/title-of-post.html and they click a link that links to ../../archives/2-2007.html will that bring them to mydomain.com/blog/archives/2-2007.html Thanks.
I have no idea on how to remove %20 using htaccess because, in my PHP script I have added the code to remove unwanted characters and make it SE friendly. I think that will be a better approach. The relative links will be working fine becoz the browser will be having no idea on whether you are using mod_rewrite or not. But I would suggest you to make the urls with respect to your homepage and set a Base Href as it will be much easier.