homepage Welcome to WebmasterWorld Guest from 107.20.25.215
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Become a Pro Member

Home / Forums Index / Code, Content, and Presentation / Apache Web Server
Forum Library, Charter, Moderators: Ocean10000 & incrediBILL & phranque

Apache Web Server Forum

    
simple Redirect Question totally Lost for solution
what I've tried so far
acimag




msg:4000477
 4:57 pm on Oct 3, 2009 (gmt 0)

I have a site that im converting from ASP to PHP. Sad part is there is over 500 pages indexed.

I know there is a way to just change the .asp to php

... I did it manually til I hit 'The Wall'
Did i mention im not going to change ANY LINK besides the .asp extention to php

I was doing in the HTACCESS

RewriteRule ^Contact_Messages.asphttp://www.TheDomain.com/Contact_Messages.php[R=301]
Any pages without variables Bingo I was fine.

Then I hit the wall..

Riddle me this... How do i...

RewriteRule ^Ads_Logos.asp?Loc=North Carolinahttp://www.TheDomain.com/Ads_Logos.php?Loc=North Carolina[R=301]

When i put that in it's just a white screen.

I know there is a 3 line code that will just rewrite it. Is there a generator or is there away I can praise someone add add the thread to my delicious account. I've read the tutorials on every site and none make sense to me.

Im not writing them to www.TheDomain.com/North_Carolina_Ads_Logos.php Im leaving As is the client is well found so we are just going to leave well enough alone. Any help?

Thanks in advance. I know ALOT of people are confused when it comes to this type of function.. Well the noobs I talk too anyway.


RewriteRule ^area-we-can-fly-aerial-ads-to-banner-tow.asp?Location=http://www.aerialadsusa.com/area-we-can-fly-aerial-ads-to-banner-tow.php?Location=[R=301]

 

jd01




msg:4000479
 5:05 pm on Oct 3, 2009 (gmt 0)

There's really no need to redirect any of the pages, in fact I recommend you don't.
This will Rewrite all the .asp urls to the php equivalent:

RewriteEngine on
RewriteRule ^([^.]+)\.asp$ /$1.php [L]

Using this nothing, including the links or URLs change from the front end. It stays exactly the same as it is now (or was yesterday :).

If you are having issues with the Query_String, you might need to use QUERY STRING APPEND:

RewriteRule ^([^.]+)\.asp$ /$1.php [QSA,L]

And I'm not sure if it's a typo or not, but you should have a space between the left side of your rule and the right... IOW: there should be a space before http: in your examples.

jdMorgan




msg:4000488
 5:29 pm on Oct 3, 2009 (gmt 0)

[QSA] is only needed if the RewriteRule substitution contains a query string *and* you wish to *append* that new query-string to any existing query string which was attached to the originally-requested URL-path.

In the absence of any query string in the RewriteRule substitution, any query string attached to the originally-requested URL-path will be passed through the RewriteRule unchanged by default.

Jim

acimag




msg:4000489
 5:33 pm on Oct 3, 2009 (gmt 0)

I just tried that.
Im on a development server so i feel that This is why the code is not working.

Would that work if i was on the www.RealDomain.com address

is there a temporary way to just make this rule work with:
[174.1xx.#*$!.#*$!...]

to rewrite it to
[174.1xx.#*$!.#*$!...]

?

jd01




msg:4000490
 5:42 pm on Oct 3, 2009 (gmt 0)

[QSA] is only needed if the RewriteRule substitution contains a query string *and* you wish to *append* that new query-string to any existing query string which was attached to the originally-requested URL-path.

In the absence of any query string in the RewriteRule substitution, any query string attached to the originally-requested URL-path will be passed through the RewriteRule unchanged by default.

Yeah, I added the second example, because I had one host where I had to use QSA when I shouldn't according to the book. I also remember copying and pasting working code here from the .htaccess file there and part of it was 'wrong' and wouldn't work when I changed hosts, but was the only way I could get it to work there. No clue as to why, but sometimes one host I had did some goofy stuff for me and I wanted to make sure I covered the question...

acimag




msg:4000497
 5:53 pm on Oct 3, 2009 (gmt 0)

so your saying that i need to add the QSA into the [ ] or anything after the .asp?Location will be ignored..

acimag




msg:4000498
 5:55 pm on Oct 3, 2009 (gmt 0)

Is there a way I can test this in a Development directory I have not updated the name server and want to test this before google throws a hissy fit and all our hard work is for nothing.

jd01




msg:4000499
 5:56 pm on Oct 3, 2009 (gmt 0)

Would that work if i was on the www.RealDomain.com address.

Yes. To see an example, put up a /test/ directory on the website.
Create an .htaccess file in the test directory with the rule I gave you in it, but edit it to this:
RewriteRule ^([^.]+)\.asp$ /test/$1.php
Upload a file called test.php to the test directory.
Type example.com/test/test.asp into your browser.
You will see the results from test.php.
Switch back to the regular rule I gave you before going live.

I'm not sure about the development server question, because I use a real site on the same host as the site I'm working with most of the time for development, because I want to know how what I'm going to do actually functions at the host I'm using, so I code on a different site on the same server (or in a directory of the live site) rather than a 'development server'.

[edited by: jd01 at 5:58 pm (utc) on Oct. 3, 2009]

acimag




msg:4000500
 5:56 pm on Oct 3, 2009 (gmt 0)

I tried
RewriteRule ^~ads/([^.]+)\.asp$ /$1.php [QSA,L]

no work

jd01




msg:4000502
 5:59 pm on Oct 3, 2009 (gmt 0)

See my previous post...
I edited it a bit and we were posting at the same time.

acimag




msg:4000503
 6:00 pm on Oct 3, 2009 (gmt 0)

Thanks for the answer. Unfortunitly the old site is on a windows box... I switched for tighter security. So i cannot test this until I put the site live. I will launch and try. i'll just hope the google bot doesnt come. Monitor this thread if all hell breaks loose! I know you guys are great and much appreciated.

jd01




msg:4000504
 6:02 pm on Oct 3, 2009 (gmt 0)

so your saying that i need to add the QSA into the [ ] or anything after the .asp?Location will be ignored..

No. You should not. I was explaining to Jim why I posted the second example. The first one *should* work, but in one case it did not for me and I had to use the second... You should Not need QSA.

acimag




msg:4000505
 6:03 pm on Oct 3, 2009 (gmt 0)

Last questions. As long as I put the QSA in it will not strip the rest of the statement. The loc variable is important and I cannot lose anything after the .asp. Some pages use the Querystring and some do not. This won't be a problem?

Meaning sometimes i:

www.domain.com/about_us.asp

and sometimes

www.domain.com/about_us.asp?Loc=Georgia_branch

It will use the variable to sub in Georgia Branch into the text & meta tags.

... Thanks again.

jdMorgan




msg:4000506
 6:03 pm on Oct 3, 2009 (gmt 0)

"~ads/" may not be visible to RewriteRule (this looks like you're using mod_userdir), so try it with and without.

If they're not already present, you will need the directives

Options +FollowSymLinks
RewriteEngine on

at the top of the RewriteRule section.

Jim

jd01




msg:4000507
 6:04 pm on Oct 3, 2009 (gmt 0)

So i cannot test this until I put the site live. I will launch and try. i'll just hope the google bot doesnt come. Monitor this thread if all hell breaks loose! I know you guys are great and much appreciated.

If you already have access to the new server, you should be able to try what I suggested with a test directory, or even in the root. I do not recommend testing it on the working site, even though I am confident it will work.

It should work on the IP address, because it's an internal rewrite...

jdMorgan




msg:4000508
 6:06 pm on Oct 3, 2009 (gmt 0)

If you didn't read what I posted previously, you do not need [QSA] because you're not appending any *new* query data... So including [QSA] is a waste of time -- on each and every HTTP request to your server.

Jim

acimag




msg:4000513
 6:15 pm on Oct 3, 2009 (gmt 0)

You guys ready to learn something. I got it to work completely. and ontop of that you guys are better then i thought. originally i was going to write it to the php extention and switch everything. Instead you lead me down a better path and now google wont even know i switched it from .asp to .php(at heart)

So
RewriteRule ^([^.]+)\.asp$ [174.1xx.1xx.1x...] [L]

Now i dont have to even do a rewrite or change to .php.

You guys are great. I know what you mean now in the beginning of the thread about don't change anything. It masks. You guys are Excellant!

jdMorgan




msg:4000522
 6:30 pm on Oct 3, 2009 (gmt 0)

That is an external 302-redirect, and I advise you *not* to use that approach, because it *will* reveal your change to the search engines...

If the code jd01 posted doesn't work with or without "~ads/" in the RewriteRule pattern, try this instead:

RewriteRule ^([^.]+)\.asp$ /~ads/$1.php [L]

(mod_userdir is complicating things here, but yes, there is an internal rewrite solution that will work. It will just take some experimenting and possibly some examination of the server error log files to get it right.)

Jim

acimag




msg:4000523
 6:38 pm on Oct 3, 2009 (gmt 0)

JD your write. Its just temporary. So i can test it on the server. im going to remove the ip/~ads once i got live. I just wanted to see if it would ever work. We use that trick at work when we are working on a site that is offline or still on another server as we develope it. thanks.

acimag




msg:4000524
 6:40 pm on Oct 3, 2009 (gmt 0)

I took the IP out and it still works. so thanks again. When it goes live ill be able to remove the /~ads/ as well correct?

It's just because im calling the site by IP that i need to include that... correct?

jdMorgan




msg:4000562
 7:50 pm on Oct 3, 2009 (gmt 0)

No, it's because you're using mod_userdir to add 'virtual' users on this test server. See Apache mod_userdir documentation for details.

Whatever rule you settle on, it should end up requiring your 'usual and customary' tweaks to go from your test server to your live server.

Jim

g1smd




msg:4001128
 1:48 am on Oct 5, 2009 (gmt 0)

If the rule contains a domain name or IP address then it will be a redirect. You do NOT want a redirect. Make sure the rule is coded as a rewrite.

acimag




msg:4001170
 3:43 am on Oct 5, 2009 (gmt 0)

Bottom line. When i go live. If i use

RewriteRule ^([^.]+)\.asp$ /$1.php [L]

is that all i need and ill be fine.

I understand using

RewriteRule ^([^.]+)\.asp$ THEIP/~ads/$1.php [L]

is just temporary when i stip that I should be OK?

jd01




msg:4001174
 3:49 am on Oct 5, 2009 (gmt 0)

Speculatively, yes and if not, then you know exactly what you need to adjust and should be done within a matter of minutes, if not seconds, depending on how long it takes you to save, type, clear your browser cache, click refresh and then adjust and repeat the process if necessary.

acimag




msg:4006345
 4:30 pm on Oct 13, 2009 (gmt 0)

JD wanted to update everyone. The code worked without a hitch. You guys are great and everything worked. Your advise it pricless

Global Options:
 top home search open messages active posts  
 

Home / Forums Index / Code, Content, and Presentation / Apache Web Server
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved