Forum Moderators: phranque

Message Too Old, No Replies

htaccess with Variable Redux

trouble parsing a variable in .htaccess

         

BigEdinTX

11:53 am on Apr 16, 2010 (gmt 0)

10+ Year Member



I am having trouble with redirects containing a variable in the .htaccess file. I have seen other code on the site, but plagiarism has not worked.

I have tested a simple redirect and it works.
But the redirect below falls to an ErrorDocument 404 and the error file says basically that www.website.com/cfm cannot be found.

The following code is not working. Help! I am a bricklayer not a software coder... so simple works better :-)

Options +FollowSymLinks
RewriteEngine on
RewriteCond %{QUERY_STRING} ^action=page&page=247$
RewriteRule ^index.cfm$ [http://example.com/services-2/more-repairs/] [R=301,L]

Here is context of the redirect with the constipating variable.
Redirect 301 /index.cfm?action=page&page=233 http://example.com/services-2/more-repairs/

thanks for the help. You just might save my last few remaining hairs on my head.

[edited by: jdMorgan at 4:27 pm (utc) on Apr 16, 2010]
[edit reason] example.com [/edit]

jdMorgan

4:32 pm on Apr 16, 2010 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



The 4th course from the top needs a bit of re-pointing. I'd suggest:

Options +FollowSymLinks
RewriteEngine on
#
RewriteCond %{QUERY_STRING} ^action=page&page=247$
RewriteRule ^inde[b]x\.c[/b]fm$ [b]ht[/b]tp://example.com/services-2/more-repair[b]s/?[/b] [R=301,[b]L][/b]

Hopefully, you can feather-in those changes and match the existing color. :)

Jim (also in TX)

BigEdinTX

5:26 pm on Apr 16, 2010 (gmt 0)

10+ Year Member



thanks, Jim for the help. However, still no lights.

the error code says 'File does not exist: /home/j#*$!x7/public_html/example.com/index.cfm

this is my translation of your remarks below.

Options +FollowSymLinks
RewriteEngine on
#
RewriteCond %{QUERY_STRING} ^action=page&page=247$
RewriteRule ^index\.cfm$ http://example.com/services-2/-repairs/? [R=301,L]

Here is context of the redirect with the constipating variable.
Redirect 301 /index.cfm?action=page&page=247 http://example.com/services-2/more-repairs/

jdMorgan

1:29 am on Apr 17, 2010 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



The Code I posted will redirect your request for
http://example.com/index.cfm?action=page&page=247 to the new URL http://example.com/services-2/-repairs/

This new URL must physically exist, or you must have a rule in place to internally rewrite it to a script that will generate a "page" for it.

This assumes that you're on an Apache server, that mod_rewrite is available for use, that you have commented-out the "Redirect 301" line you showed above, and that you have deleted your browser cache before testing any new server-side code (like this rule).

But most importantly, is the above description of the code's function what you want to do?

Jim

BigEdinTX

3:11 am on Apr 17, 2010 (gmt 0)

10+ Year Member



Yes, that is exactly what I want to do, and I had no realization of the context required to make this work.
I am on an Apache server,
I will verify mod_rewrite,
I will comment out the Redirect 301 line that is applicable here and
I will delete my browser cache, or try it on another computer.

Thanks, Jim, I will let you know what happens.

BigEdinTX

1:45 pm on Apr 17, 2010 (gmt 0)

10+ Year Member



After crashing my website using <echo> in .htaccess ( I was commenting out the line - small boys and big hammers do not always mix- ) I went back to domain support at gator hosting company.
They had sort of sent me on my way with a link to the apache manual and later a link into a condition solution with php
here at webmaster world.

So I arrived here, Jim, and you were a big help.

So back to my story and then I will show you the prize hen.
I asked my host company support about mod rewrite and I got back a complete solution to my challenge.

Here is the text as I got it. I hope your webmaster technology does not translate away the nuance.

And I will also reinsert the code which was wanted but would not compute because of the conditions in the URL.

http://example.com/index.cfm?action=page&page=247 to the new URL http://example.com/services-2/-repairs/

Here is the winning entry.

RewriteCond %{QUERY_STRING} ^action\=page\&page\=247$
RewriteRule ^index\.cfm$ http://example.com/services-2/-repairs/? [R=301,L]

I was also modifying the wrong htaccess file. There was a separate one in the file for the redirected website. I was messing with both this one and the .htaccess in the main directory and creating mud.

But all is working and I can now decide how to part my few remaining hairs on my balding head.

g1smd

5:57 pm on Apr 17, 2010 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Both the = and & symbols don't need escaping.

jdMorgan

6:15 pm on Apr 17, 2010 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Yes, and if you remove the unnecessary escaping, it looks exactly like something I wrote very, very recently... :)

Jim

g1smd

7:24 pm on Apr 17, 2010 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Oh, yes, just that one has the word 'more' in it and the other does not.