Forum Moderators: phranque
I have recently upgraded from PHPNews to WordPress to maintain my blog. I have about 100 posts on PHPNews which I am going to transfer. However, for backward compatibility, I would like internal legacy links to be maintained. Can I do this with mod_rewrite?
The old links are in the style of:
[example.com...]
The replacement URL would be:
[example.com...]
So you can see there is no logical equivalence rule - it's case by case and I would need to have a separate rule for each article. This isn't really a problem for a relatively small number of articles.
I don't want the URL in the browser to be re-written.
If anyone can suggest a way of doing this I would be really grateful.
Andy
Welcome to WebmasterWorld [webmasterworld.com]!
Just a series of RewriteRules -- one for each old URL -- is all you need. In order to minimize any performance impact, put them in the .htaccess file in the "news" subdirectory, or within a <directory> container in http.conf that limits their action to the "news" subdirectory.
In order to avoid updating the URL, you'll need to use an internal rewrite as opposed to an external redirect. mod_rewrite can do either. However, if you want those old URLs updated to the new ones in search engine listings, I'd recommend using a 301 redirect.
Jim
We'll be happy to help you get your code working, but our charter [webmasterworld.com] requires you to give it a try first. See the references below. You can also search this site for examples to work from.
Apache mod_rewrite documentation [httpd.apache.org]
Apache URL Rewriting Guide [httpd.apache.org]
Regular Expressions Tutorial [etext.lib.virginia.edu]
Jim
It's far better to give a man tools so that he can plant and harvest his own bread - but if you tell him to go figure out how to sow, reap and bake for himself and come back with an attempt to feed himself, he will die. Give him some good tasting bread, just enough to give him the strength to see that it is good - and then teach him by example (for the original manual on baking bread is in a very detailed technical language he has not the strength to understand without nourishment) - then he will understand better and bake better bread for himself and his family.
Never mind - I worked it out and don't feel satisfaction as it still isn't fully explained. But there you go. Your charter remains intact at keast for my post.
Those who are willing to do a little study and make an honest attempt to write their own code will end up understanding enough to use mod_rewrite safely. Those who don't make the attempt will either crash their site or come back here repeatedly asking for "on-going free support." This is not a help desk, it's a discussion forum; we discuss methods of solving problems, rather than offering one-off solutions. We simply don't have enough contributors here to sustain that kind of forum. Most of the contributors here have to make a living in addition to posting here, and asking them to write the code for every unique request is simply asking too much.
I inherited the forum policy, and I think it's a good one, even if I can't articulate the reasons succinctly.
Jim
I thought the point of a discussion forum of this nature was to help people who have gone to the manual - but found it difficult to follow (even the header of the manual effectively admits that!) - to write good code and use the web server more efficiently.
The implication of what you've replied to me is that I am lazy and haven't bothered. I actually spent about 5-10 hours working through the Apache manuals and other online material, testing code, working out regexp, realising this wasn't enough on its own, looking at Rewriterules and ocnditions and bases and engines...
I have successfully written my own redirection code (and other stuff) in other circumstances, but not like this where it involved a query string. Maybe I should have known this, but I didn't. I did phrase my question in such a way as to request an example, an explanation. I only asked for an example code because the first reply (1) didn't even address the actual problem and (2) it just said you can use a RewriteRule, which isn't actually true.
I didn't crash my server in the process of testing things out. And I am not going to keep coming back here lazily asking for "ongoing free support".
No direct criticism of you was intended; My scenario description was based on what actually does happen. "Lazy" was your word, not mine; I suspect it is not primarily laziness, but unfamiliarity with a new subject, that prompts people to ask for a solution. They don't realize that additional complexity can arise because of differences in server configuration, precise location of mod_rewrite code installation, and many other facters that they will need to be prepared to recognize. Without a basic study of mod_rewrite and its terminology, a new mod_rewrite user may still be lost, even with a working code snippet.
The difference between "write my code for me" and "please post an example based on my requirements" is one of phrasing, but is in practice inconsequential -- any forum contributor replying to the latter would naturally attempt to do the former, leaving no practical difference. To post an example that did not directly solve the problem would be a disservice *and* it would take just as much time as a direct solution.
I will alter my response to "write my code for me" posts to include the phrase "post your code and ask a specific question, please" to prevent this type of problem in the future.
Jim