Forum Moderators: phranque
[snip]/bric-a-brac_detail.php?item=BAB%204-14
...and I would like to redirect to this:
[snip]/bric-a-brac_detail/BAB_4-14.html
...so this is what I coded:
RewriteEngine on
RewriteBase /[snip]/[snip]/[snip]/
RewriteRule ^bric-a-brac_detail\.php\?item=BAB\%20([^/]+)$ bric-a-brac_detail/BAB_$1\.html [R=301,L]
...and it simply won't take, I keep getting the original URL/query (which by the way leads to an empty page).
I've obviously missed escaping something or something silly of the like but I can't seem to see what it is though I've been at it for more than two hours. Can anyone help me with this?
Thank you very much in advance,
Josefu.
I sent that in, and it apparently "took effect".
The result was that NONE of my pages, even .html ones would work any more, ALL of them gave some arcane error message .. in effect my site was dead in the water.
I immediately rewrote .htaccess to read simply RewriteEngine off and damned quickly. I got the site back up, but I was almost in a panic.
I wish like h*** somebody would make a webmaster interface with commands like:
IF (offsite pages) CALL (.gif OR .jpg)
THEN { redirect(nasty.gif OR worse.jpg};
I suppose that makes too much sense.
The semicolon ; means 'end of statement' so others may follow.
Best wishes, apologies, and good luck
- Larry
.
Thanks for trying but cuttin' and copying from a webpage direct to your .htaccess is a baaaaaad idea. Sounds like that's what you did, anyways. Even the 'whitespace' in a web page can hold 'odd' characters.
I asked the above question as I have to move on from staring dumbly at a single line of code for over two hours. If and when I find the solution I'll close this thread... but it's still up in the air so any suggestions would be welcome.
Thank you,
Josefu.
The problem here is that a query string is not considered as part of the URL; It is data to be passed to the reource specified by the URL. This gets into the definition of URLs, but for our purposes, all we need to know is "that's how it is." As a result, you must treat the query string separately using RewriteCond:
RewriteEngine on
RewriteBase /[snip]/[snip]/[snip]/
RewriteCond %{QUERY_STRING} ^item=BAB\%20([^/]+)$
RewriteRule ^bric-a-brac_detail\.php$ bric-a-brac_detail/BAB_%1.html [R=301,L]
I cannot comment on whether your RewriteBase is correct or not, since it is "snipped" and I don't know your site.
LarryHat,
You might want to do a WebmasterWorld site search using Google for threads about image hotlinking -- We have a lot of them. There are also several references listed in our charter [webmasterworld.com] that may help you to understand how the code works and how the various anti-hotlinking examples differ. If you find nothing useful, please start a new thread, as hotlinking is off-topic for this one.
Jim
I am new to both PHP and Apache - as you can tell I'm sure. I was not aware that a query isn't considered by Apache as being part of the URL - or aware that Apache could even differentiate between the two. Perhaps I should have done a search of my own first : P
Thanks for putting me back on track, take care,
Josefu.
<added>And after a little more reading (in the right direction) I found that I can cut the query altogether by adding an extra "?" after "html" in the replacement string. Actually your solution just opened up a whole new realm of possibilities for me. Thanks again! </added>