: Poor Man's Clean URLs vs. Mod_Rewrite At the company where I work, we're getting ready to design a new web site, and there's some disagreement about how to do clean URLs. Over the past year
At the company where I work, we're getting ready to design a new web site, and there's some disagreement about how to do clean URLs. Over the past year we've been making small improvements to our existing web site in anticipation of a large-scale redesign, which has involved the Poor Man's Clean URLs™.
Example: www.example.com/products/widgets/index.php www.example.com/products/sprockets/index.php
For the new site, there is some talk about using mod_rewrite:
The user requests www.example.com/products/widgets/ mod_rewrite sends them to www.example.com/index.php?page=products/widgets index.php sends them to the real page www.example.com/products/widgets.php
I'm failing to see how all this rigamaroll is adding any value. The employee in favor of mod_rewrite is claiming that fewer directories somehow equates to easier maintenance.
None of our existing pages make use of variables in the query string. All the content is in the actual files themselves. We are planning to put some content in the database, like press releases and upcoming trade shows we will be attending, but the vast majority of pages will only be using PHP for including common HTML like header, footer, and navigation. I would definitely be up for using mod_rewrite for dynamic content like that.
Is there some big benefit I'm missing that we should be using mod_rewrite for everything? Are the Poor Man's Clean URLs™ sufficient for the non-database parts of our site?
More posts by @Connie744
6 Comments
Sorted by latest first Latest Oldest Best
"Clean URLS" often means no file ext; it helps hide implementation details from the viewer. The advantage of that is when you decide to move your site from say, PHP to Ruby on Rails, you can do so without changing a single URL.
Now, while its possible to run your site with ASP.net and have filenames ending in .php if you want to keep your URLS intact, it seems to make more sense to do them in such a way that the issue never has to come up.
www.example.com/news/2010/10/our-new-url-system/
Can always be a good URL, even if you completely change the underlying architecture, or go from static files to dynamic ones .. or the reverse.
It seems to me like have all of your content in a database would be much faster and easier to maintain then digging through a large file system each time you need to make updates. As John Mueller mentioned above the nice URL is not going to make a huge difference in your rankings, however, you want to consider using Mod_Rewrite to keep your existing URLs and their value. IE if:
example.com/widgets/index.php has 1,000 links pointing to it and you change that to be example.com/pages/widgets.php you risk losing a lot of that value (you can of course redirect it, but it's debatable whether or not that will pass the same value)
My recommendation would be if you are continuing to serve static content continue using the file system, if you are converting it to dynamic content use the Mod_Rewrite to keep your current URL structure in tact. Or if it's not possible to maintain the current structure use the Mod_Rewrite to create a structure that will be stable for future updates.
As has been said, having .php or ?page= doesn't really matter. What does matter is if you're doing something like this:
www.example.com/index.php?page=13
What you refer to as the "Poor Man's Clean URLs" is just clean URLs implemented through the filesystem. You can have those types of URLs using mod_rewrite, just as you can have the second type of URL without mod_rewrite.
Clean URLs are exactly what the name implies—URLs that are clean or look clean. Both
yoursite/foo/bar
and
yoursite/foo/bar.php
are clean URLs. The term "clean URLs" doesn't specify any particular implementation. You can implement clean URLs by generating cached .html pages every time the site is updated if you want. mod_rewrite simply lets you decouple URL structure from file structure without redirects or frames.
From what it sounds like, you're not currently running a database-driven site. And although it might technically qualify as a dynamic website, it's probably more on the static end of the spectrum if you're mostly using PHP just to include headers/footers. That is fine for small sites that rarely need updating, but as your site gets bigger, you'll need to implement a real CMS.
Where mod_rewrite shines is when you start taking maintainability into consideration. Instead of having hundreds of php files for each and every product page (with lots of redundant code), you can simply have a single script that handles all requests. But if you no longer have a one-to-one mapping of actual .php files to displayed web pages, then you'll need to use something like mod_rewrite to route the page requests intelligently while maintaining the illusion of the file/directory structure being there.
So it's not the extra subdirectory that you should be worried about. It's the fact that you're creating a separate .php script for every page on your site.
It's a myth that "/pagename" or "/pagename.htm" are better for search engines than "/pagename.php". At least at Google, there is definitely no basis for this (and I assume the others as well). Similarly, even "index.php?page=pagename" does not need to be rewritten as "/pagename" -- search engines can understand those URLs without any problems, and Google has even gone on the record that it prefers that users not rewrite them unnecessarily ( googlewebmastercentral.blogspot.com/2008/09/dynamic-urls-vs-static-urls.html ). So provided you aren't creating endless URLs with URL parameters, rewritten URLs are not necessarily more search engine friendly than non-rewritten URLs.
That said, users may prefer nice URLs over ugly/complex URLs. If your main worry is having nice URLs in the search results, I'd take a look at the breadcrumbs microformat that Google now supports ( googlewebmastercentral.blogspot.com/2010/09/rich-snippets-testing-tool-improvements.html ) as these can often provide an even better user-experience regarding URLs in the search results. This won't solve the problem of users wanting nice-looking URLs to link to, but provided your URLs are not endlessly complex (and your examples aren't), it likely won't make a measurable difference if you rewrite them for that use-case. If there's no measurable difference, then it probably doesn't make sense to spend time on designing and maintaining such a setup.
The 3 step process you outlined above seems redundant and useless as is stated above. If in step 3 index.php takes them to the "real" page then why even bother with mod_rewrite at all? Doing that will negate the advantages mod_rewrite is offering. Namely, a search engine friendly URL and easier site maintenance. If you stop at step two you benefit from mod_rewrite by having only one page to maintain yet it can serve up a virtually unlimited number of pages and be transparent to the user and the search engines as they only see the URL in step 1.
Terms of Use Create Support ticket Your support tickets Stock Market News! © vmapp.org2024 All Rights reserved.