Forum Moderators: phranque
Neither of these redirect instructions do anything:-
#Redirect any /index.php/ addresses to our normal one
Redirect permanent /index.php/ http://www.example.com/Redirect 301 /index.php?file=profile&mode=viewprofile&u=3 http://www.example.com/myprofile.html
Any thoughts on what I've done wrong?
Thanks,
TJ
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{HTTP_HOST} $ [NC]
RewriteRule ^(.*)$ [newdomain.com...] [R=301,L]
</IfModule>
So you mean do this:-
Redirect permanent /index.php http://www.example.com/
?
I tried that and the site fell over (wouldn't load any pages at all), which was interesting!
I've tried both "Redirect permanent" and "Redirect 301" also.
This precedes the commands:-
# first let's deny the ip's we don't like
order allow,deny<Various spammers in here ;-)>
allow from all
<Redirects start here>
As I understand it, .htaccess is read from the top down, so I don't think there can be anything lower down the file messing this up.....?
Thanks,
TJ
RewriteCond %{DOCUMENT_URI} index\.php$ [NC]
RewriteRule .* http://www.example.com/ [R=301,L]
By the way, if the new index file is named "index.php" this code will create an infinite loop, and the page will not load.
Thanks.
The first one didn't work. I preceded it with RewriteEngine On as I assume I should do?
I haven't tried the second as I take your point about infinite loops. Is there any way around that problem incidentally?
Jim - ah, you edited before I could reply. But yes, it is all voodoo to most of us I think.... ;-)
RewriteEngine on
Options +FollowSymLinks
RewriteCond %{REQUEST_URI} ^/index\.php$ [NC]
RewriteCond %{QUERY_STRING} ^file=profile&mode=viewprofile&u=3$ [NC]
RewriteRule .* http://www.example.com/myprofile.html [R=301,L]
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /index\.php\ HTTP/
RewriteRule ^index\.php$ http://www.example.com/ [R=301,L]
DOCUMENT_URI on Perl is equivalent to REQUEST_URI on Apache. Apache doesn't have a DOCUMENT_URI environmental variable.
REQUEST_URI on Perl is the requested document/path/query string.
You can see how confusing it is for someone who programs in Perl all day long. It would be so much easier if they were on the same page with respect to environmental variables.
Got another slight problem. I assumed that I could have several of these, eg:-
RewriteCond %{QUERY_STRING} ^name=PNphpBB2&file=profile&mode=viewprofile&u=3$ [NC]
RewriteRule .* http://www.example.com/myprofile.html [R=301,L]
RewriteCond %{QUERY_STRING} ^name=PNphpBB2&file=profile&mode=viewprofile&u=2$ [NC]
RewriteRule .* http://www.example.com/hisprofile.html [R=301,L]
Again, I seem to get stuck in a loop - the second one seems to "stall".
Any thoughts, or is what I'm trying to do here impossible?
Thanks!
TJ
RewriteEngine on
Options +FollowSymLinks
RewriteCond %{REQUEST_URI} ^/index\.php$ [NC]
RewriteCond %{QUERY_STRING} ^name=PNphpBB2&file=profile&mode=viewprofile&u=3$ [NC]
RewriteRule .* http://www.example.com/myprofile.html [R=301,L]
RewriteCond %{REQUEST_URI} ^/index\.php$ [NC]
RewriteCond %{QUERY_STRING} ^name=PNphpBB2&file=profile&mode=viewprofile&u=2$ [NC]
RewriteRule .* http://www.example.com/hisprofile.html [R=301,L]
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /index\.php\ HTTP/
RewriteRule ^index\.php$ http://www.example.com/ [R=301,L]
RewriteEngine on
Options +FollowSymLinks
#
RewriteCond %{QUERY_STRING} ^name=PNphpBB2&file=profile&mode=viewprofile&u=3$ [NC]
RewriteRule [b]^index\.php$[/b] http://www.example.com/myprofile.html [NC,R=301,L]
#
RewriteCond %{QUERY_STRING} ^name=PNphpBB2&file=profile&mode=viewprofile&u=2$ [NC]
RewriteRule [b]^index\.php$[/b] http://www.example.com/hisprofile.html [NC,R=301,L]
#
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /index\.php\ HTTP/
RewriteRule ^index\.php$ http://www.example.com/ [R=301,L]
Jim - OK, working as expected now, except that the server appears to be returning a 200 OK and the URL in the address bar shows the "old" URL.
From the WebmasterWorld header check tool:-
HTTP/1.1 200 OK
Date: Sun, 12 Mar 2006 18:05:46 GMT
Server: Apache/2.0.46 (Red Hat)
Last-Modified: Sun, 12 Mar 2006 12:31:30 GMT
ETag: "4d81ba-1437-67d4ec80"
Accept-Ranges: bytes
Content-Length: 5175
Connection: close
Content-Type: text/html; charset=UTF-8
That's when I enter:-
http://www.example.com?name=PNphpBB2&file=profile&mode=viewprofile&u=2 I've now got these lines right at the bottom of my .htaccess. Could it be something above them that's causing the 200 to be served rather than the 301?
Thanks again!
TJ
<Added>
Ah - it actually seems to be redirecting, but including the variables which are no longer required, so when I enter the original link:-
www.example.com?name=PNphpBB2&file=profile&mode=viewprofile&u=2 I get taken to:-
www.example.com/[b]hisprofile.html[/b]?name=PNphpBB2&file=profile&mode=viewprofile&u=2 .... and I get a 200 OK where I would expect to see a 301 in the header?
hisprofile.html is a static page - the additional variables are not required by it.