View Full Version : htaccess coding help
-=Seth=-
08-31-2007, 08:04 PM
This is a 301 redirect i was trying to do in my htaccess file, unfortunately it doesnt work and i cant figure out why
Redirect 301 /index.php?act=viewCat&catId=75 http://www.grooming-health.com/proraso.htm
Redirect 301 /index.php?act=viewCat&catId=84 http://www.grooming-health.com/dovo-solingen.htm
can anybody see what i'm doing wrong, thanks
webado
08-31-2007, 08:16 PM
It's because of the query string.
You need the mod rewrite module.
You need to test the query string and redirect that way.
Can't test it now though, I need to be at home.
Try thsi:
Options +Indexes +FollowSymlinks
RewriteEngine on
RewriteBase /
RewriteCond %{QUERY_STRING} ^act=viewCat&catId=75 [nc]
RewriteRule ^(.*)$ http://www.grooming-health.com/proraso.htm [L,R=301]
RewriteCond %{QUERY_STRING} ^act=viewCat&catId=85 [nc]
RewriteRule ^(.*)$ http://www.grooming-health.com/dovo-solingen.htm [L,R=301]
fuzzy
09-01-2007, 06:27 AM
I once tried using a regular 301 for a php query, found out it didn't work. And that was all I really needed to know.
When I started working on my own self-coded php project, I made sure I built in an automatic 301 redirect...
Regardless, I'll have to keep Christina's advice in mind! I might still need that one day... 8-)
-=Seth=-
09-01-2007, 04:05 PM
okay i've been playing around with this for hours and i'm beginning to think i'm out of depth
is it normal for different types of browser to interpret htaccess files in different ways, i managed to get the coding you gave me (thanks for that Christina) working but only in explorer and using the pointers you gave me i got this:
RewriteEngine on
RewriteRule ^index./php?act=viewCat&catId=75$ http://www.grooming-health.com/proraso.htm [R=301,L]however it only works in firefox, nothing seems to work in both, also my main concern is google, i dont want to lose the benefit of links coming in to pages that no longer exist, so if browsers dont see it the same hows google going to see it
im stuck can anybody give me anymore pointers in why i'm messing up.
webado
09-01-2007, 05:58 PM
That's not what I gave you. I gave you directives based on the query string. Did you try it as I gave it?
Not saying it works because it doesn't actually. But this is the kind of thing that needs to be done, along those lines.
Browsers do not interpret .htaccess, they are unaware of it completely. The server acts on its directives regardless of browser or user agent unless the .htaccess fiel has directives based on user agent - I doubt you got any of those.
The only differences I can see between FF and IE would be that in FF it's easy to suppress referrer with the developer toolbar, but there's no such option in IE I'm aware of. Again this would only matter if your .htaccess tests the referrer, which is doesn't.
So I'll keep on thinking because I too need an .htaccess solution for this if it's possible at all.
In the meanwhile I am handling a similar situation with a bit of php code at the top of index.php that tests the query string part by testing $_SERVER['REQUEST_URI'] (NB: not the php variable $_SERVER['QUERY_STRING']), isolating the string between ? and end of the string, testing that, and then do a 301 redirect to wherever if it matches.
Here is where I am testing:
client.webado.net/seth/
And this is the script I put at the top of my index.php :
<?php
$request_uri=$_SERVER['REQUEST_URI'];
$qm = strpos($request_uri,"?act=viewCat&catId=75");
if ($qm) {
$goto = "http://www.grooming-health.com/proraso.htm";
header("Location: $goto");
exit;
}
$qm = strpos($request_uri,"?act=viewCat&catId=85");
if ($qm) {
$goto = "http://www.grooming-health.com/dovo-solingen.htm";
header("Location: $goto");
exit;
}
?>
-=Seth=-
09-01-2007, 07:15 PM
the original code you gave me worked in firefox but no joy in explorer, i used what you said and searched google under mod rewrite, thats how i developed the second code, (it doesnt work either)
i also found a blog which said htaccess was all voodoo which is beginning to sound plausible
so do i need to stick closer to the original code you gave me, i'll go back and start searching again, thanks Christina
webado
09-01-2007, 07:21 PM
Until you or I find it, do what I just did above.
The problem with the code I gave for .htaccess is that it does not chop the query string, it tacks it onto the new url where you are redirecting. I need the bit of voodoo to know how to get rid of that. I am getting a headache from reading the Apache manual on this.
webado
09-01-2007, 09:34 PM
I FOUND IT!
Options +Indexes +FollowSymlinks
RewriteEngine on
RewriteCond %{QUERY_STRING} ^act=viewCat&catId=75$ [NC]
RewriteRule index.php http://www.grooming-health.com/proraso.htm? [R=301,L]
RewriteCond %{QUERY_STRING} ^act=viewCat&catId=85$ [NC]
RewriteRule index.php http://www.grooming-health.com/dovo-solingen.htm? [R=301,L]
-=Seth=-
09-02-2007, 08:34 AM
ha ha that works, Christina you are a babe
i got hundreds of those old php pages this is gonna clear up thousands of 404 errors a month
Christina you are without doubt my favorite online imaginary friend, thanks babe youre great
webado
09-02-2007, 12:50 PM
ha ha that works, Christina you are a babe
i got hundreds of those old php pages this is gonna clear up thousands of 404 errors a month
Christina you are without doubt my favorite online imaginary friend, thanks babe youre great
Oooooh, Seth, you make me blush! :oops: *** batting eyelashes ***
But hundreds? Yikes, you're gonna have a lot of lines in your .htaccess file.
You'll need some automation whether you use .htaccess or scripting methinks.
Basically this does externally the opposite of what your url rewriting does internally.
Do you have your current internal url rewriting automated in any way? Or did you add them all manually to your .htaccess file?
-=Seth=-
09-02-2007, 01:48 PM
er no i'm just hand coding and its a pretty big file, 335 lines when i include all the redirects, the error docs, and a big wad of blocks for bad spiders i found online
is that size going to be a problem
to be honest i was intending to make it bigger, people keep trying to go to certain pages leaving gaps between words giving me "% 20" in the query string i was just trying to figure out how you do '%20' in htaccess
webado
09-02-2007, 04:08 PM
I'd say if people are trying to put in query strings for notions that don't exist give them a 404 and be done.
I know, easier said than done :lol:
I'm not sure how to validate query strings to allow only certain parameters and only in a certain order. Surely there's a way, I just don't know it.
vBulletin® v3.8.2, Copyright ©2000-2009, Jelsoft Enterprises Ltd.