Forum Moderators: bakedjake
mydomain.com/a1.htmland return the output from
mydomain.com/mytemplate.php?page=a1Simple, no?
I can simulate at home on my server and get results with:
RewriteEngine on
RewriteRule ^(.*)\.html$ /mytemplate.php?page=$1
[edited by: mipapage at 10:58 pm (utc) on May 21, 2003]
But once on the live site I am asked to stick a 'RewriteBase /' into the .htaccess file, at which point things stop working.
When I print my variables, instead of returning 'a1', it returns either www./ai or _./a1 ...
Any ideas as to what may be happening?
> on the live site I am asked to stick a 'RewriteBase /' into the .htaccess file
Who asks you to do this? What happens if you leave it out?
Sometimes, looking at the error log files will give a good indication of when you really must use RewriteBase, because the rewritten request will generate a 404-Not Found error in that case.
Ref: [httpd.apache.org...]
Jim
Thanks for the reply. At some point last night my host changed a few settings and now it's good as gold.
However, with the rewrite rule in place, I can access the files with both the clean and the 'dirty' url.
what are the tecnical names for those? Canonical and?
How can I make it so that only the clean url gets access?
Here's the rewrite that is working:
RewriteEngine on
RewriteRule ^(.*)\.html$ /template.php?page=$1 [L]
very simple stuff, I know
Sometimes, looking at the error log files will give a good indication of when you really must use RewriteBase, because the rewritten request will generate a 404-Not Found error in that case.
One of those intuitively obvious things that I always miss, and proves that I have no talent for seeing the intuitively obvious.
I'm not sure exactly what the question is, but you could block spiders from indexing the script URLs by using robots.txt.
User-agent: *
Disallow: /template
I don't think it's necessary, though.
Since the redirect is internal, blocking by referrer, etc., would not work either. But no-one will ever "see" that /template.php?page=a1 script address - it is used only inside your server. Users and spiders will see only the mydomain.com/a1.html - type URLs.
As to my comment about the error log file, I really meant that sometimes the error log will show you an error on a screwed-up looking file path, and that helps to figure out what rewritebase is needed. Other times, the error log is useless. So, it wasn't intended as any kind of snide remark at all.
Jim
I'm not sure exactly what the question is, but you could block spiders from indexing the script URLs by using robots.txt.
What I thought was that by placing the rewrite rule, you would no longer be able to put the ...com/mytemplate.php?page=1 in the address bar and have it work.
Upon reflection, I can't see why that would be the case - it shoudl still work, no?
Is there some sort of check that I can put in that says: if it doesn't end with .html, it doesn't cut it.
I do have something in my PHP that checks the variables...
You could try this, which will redirect external script requests to your index page. Order is critical.
RewriteEngine on
RewriteRule ^(.*)\.html$ /template.php?page=$1 [L]
RewriteRule \.php$ / [R=301,L]
RewriteRule \.php$ /index.html [R=301,L]
Trying to redirect "anything but .html" would block your scripts, css, and images.
HTH,
Jim
Thanks again for the reply! Here's what happened...Oh, first, important info: if I type in only the domain, I get a blank white page, therefore this condition:
If your index page is not available using "www.yourdomain.com/"
is true. But I tried both methods anyway
Not sure if those results tell you anything. I'm going to try a couple of other things here on the local server...
Thanks again...
It sounds like your script (or something) is doing an external redirect downstream from the RewriteRules.
What is the name and filetype of your true index page? - Are all pages actually handled by the script?
RewriteEngine on
RewriteRule ^(.*)\.html$ /template.php?page=$1 [L]
RewriteRule \.php$ / [R=301,L]
You can check whether the script issues an external 301 or 302 redirect by using the WebmasterWorld Server Headers [webmasterworld.com] checker. Start with a valid "html" URL, and see if you get a 301 or 302 response back from the script, instead of a 200-OK response and the page you asked for.
So, the choice is to either live with people being able to directly access your script, or going through the PHP code to make sure that all files are <include>d rather than referenced by external redirection.
A partial solution might be to stop non-blank external referrers from accessing your script; It won't cover all cases, but it may help:
RewriteEngine on
RewriteRule ^(.*)\.html$ /template.php?page=$1 [L]
EewriteCond %{HTTP_REFERER} !^$
RewriteCond %{HTTP_REFERER} !^(www\.)?mydomain\.com [NC]
RewriteRule \.php$ - [F]
Hope you're still with me on this, it's been a few days, but I had some work to do on the site, now I'm back to trouble shooting the rewrite...
What is the name and filetype of your true index page? - Are all pages actually handled by the script?
I tried the Server Headers checker on one of the rewritten urls, and it returned "HTTP/1.1 200 OK".
My main problem is now that when you enter just the domain name, a blank page pops up. Any insight into this?
RewriteBase /
RewriteRule ^$ index.html [L]