Forum Moderators: phranque
It is written like this (I realize the rewrite could probably be written better, but this should work.):
RewriteRule ^(.*)widgets/gadgets/(.*)$ $1widgets/article.php?gadget=$2
The rewritten url should look like:
h ttp://www.mydomain.com/widgets/gadgets/wodget
When I hold my cursor over the rewritten link, it looks like it should in the status bar. When I click on the link, I can tell the browser is trying to do something. The url in the address bar even changes to the correctly rewritten url. But, the page that loads is the same one that I was just on - the one with the rewritten link.
If however I type in:
h ttp://www.mydomain.com/widgets/article.php?gadget=wodget
the page comes up correctly, so everything is ok with the database and the scripting to pull out the right article.
Any idea what the problem might be? Is it the mod_rewrite or something else? Does it have anything to do with the way mod_rewrite is set up on WestHost that might be different from the old host?
I like to start with something like:
RewriteRule ^silly\.html$ /index.html [L]
To test, you request silly.html with your browser, and you should get the contents of index.html.
If the answer is no, then you'll have to investigate differences in server configuration. In many cases, the answer is simply that one of the following two lines is missing from the beginning of the code:
Options +FollowSymLinks
RewriteEngine on
Your error log should provide some information about what the problem is.
Jim
Take a look at your error log. Your statement, "When I click on the link, I can tell the browser is trying to do something. The url in the address bar even changes to the correctly rewritten url" leads me to believe that you've got a redirection loop involved here, but perhaps due to the examplified rewrite parameters you posted, I can't spot it.
You must arrange the rewritten directory and file names such that a rewritten URL will not match the pattern in the RewriteRule; Otherwise, the URL will be rewritten again, leading to a loop. There is also the possibility that another RewriteRule may be invoked after the first Rewrite, and that the two are "ping-ponging," rewriting the URL back and forth until your server redirection limit is reached. Remember that mod_rewrite in an .htaccess context is recursive, and that all RewriteRules should have a [L] flag unless you have a specific reason to omit it. In either case, the error log will help identify the specific error.
Jim
Take a look at your error log.
I should probably do that, but I haven't even had a chance yet to see how/where to download the server logs.
Meanwhile - I was concerned about a possible looping thing too, but that would be so weird as that same mod_rewrite is still working just fine on the old site. I'm not using the [L] flag, I set this up a long time ago, I can add that though.
I think I may to just give up on this, at least temporarily, and set up the site all static, until I have more time to work on it.
I was really hoping it wouldn't be that hard to move the site, I guess I was wrong.
Here is what I use without the widgets, I don't think I'm revealing anything that would break the tos:
RewriteRule ^(.*)m-biology/concepts/(.*)$ $1m-biology/article_concepts.php?concepts=$2
The only other thing I can think of is the following that I have on the article_concepts.php file. But it is not going to the site index anyway, so I don't think that is causing it.
if (!$concepts) {
header("location:http://www.mydomain.com");
exit;
The additional code you posted apparently does a 302 external redirect. That could be interfering, but I'm not sure what that code does in the scheme of your site.
We can guess and post all day, but it really will be much more efficient to look at the host's FAQ and find out where your error log is -- or just poke around the top level of your site using FTP and see if the log files are in a folder there. Trying to debug this without the log info will probably be difficult.
Jim
even if not optimal
yeah, I've since learned how to do it better than when I first set this up. I thought it would be best to get it working how it was before, before I change anything.
The additional code
that is in case someone tried to go straight to the file article_concepts.php when a variable hasn't been passed to it.
I think the problem may be related to the host using Apache 1.3, and my other host likely used a newer version. I need to find out what the differences are between them.
jdMorgan figured out what the problem was! (Thanks again Jim!)
It turned out to be that westhost has MultiViews defaulted to On, while my old host had it defaulted to OFF.
I had to change the first part of the htaccess file to:
Options +FollowSymlinks -MultiViews
RewriteEngine on
and that took care of the problem!