Forum Moderators: phranque

Message Too Old, No Replies

Run asp/aspx page like php

I need to fool php into allowing me to run aspx as a php file

         

Brent W Peterson

6:21 pm on Jul 12, 2009 (gmt 0)

10+ Year Member



I have a client who has a ton of links out there in google etc that go to [domain...]

I need to capture the links and redirect them. I would like parse the data out and redirect to a new html friendly page (They are using Magento for the new site)

Can any one help with the basic on this?

jdMorgan

7:06 pm on Jul 12, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Rewrite all of these requests to a script using mod_rewrite, so that the script can access your/a database to construct the new/friendly URL and generate a 301-Moved Permanently response to the client.

I don't think you're actually expecting to execute aspx as php, since that won't ever work, but rather, you are simply wanting to redirect the old URLs to new URLs, and then to rewrite those new URLs (when requested from your server) to a script to generate the pages using php.

Take advantage of this opportunity to future-proof the site by eliminating all "file extensions" from your page URLs -- The files themselves will still have entensions, but the URLs don't need them. In this way, you will never have ".aspx", ".php". or ".html" in your page URLs any more. Carefully structuring your new URLs will assure that they won't need to change for any other reason, either -- ever again.

Jim

Brent W Peterson

7:13 pm on Jul 12, 2009 (gmt 0)

10+ Year Member



Here is what I have so far

Options +FollowSymLinks
RewriteEngine on
RewriteRule ProdBySubCat-SubCat-(.*)-fd-(.*)\.htm$ ProdBySubCat.aspx?SubCat=$1&fd=$2

Here is an example of the incoming URL

http://www.example.com/products/ProdBySubCat.aspx?SubCat=11166&fd=1

the new site is at

[new.example.com...]

and I have my .htaccess file in /products/

What else do I need?

[edited by: jdMorgan at 12:48 am (utc) on July 13, 2009]
[edit reason] example.com [/edit]

Brent W Peterson

7:36 pm on Jul 12, 2009 (gmt 0)

10+ Year Member



I think I found one of my problems, but it is still not working

In my root .htaccess do I need something like this to exclude the directory?

RewriteCond %{REQUEST_URI} !^/products/

jdMorgan

1:44 am on Jul 13, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I don't see any recursion potential here, so I doubt you need a RewriteCond like that.

However, if that's your incoming link posted above, then your rule is apperently backwards. The general form for a rewriterule is:


RewriteRule ^client-requested-local-URL-path$ internal-filepath or new-URL [L]

However, be aware that the query string (if any) is handled separately, and is not 'seen' by RewriteRule. To handle it, you need to use a RewriteCond, examining the %{QUERY_STRING} variable.

Also, avoid the use of ".*" subpatterns, and especially multiple ".*" subpatterns. While ".*" is fairly easy to comprehend, processing it is highly inefficient because it matches anything, everything, or nothing. Therefore, the matching engine must make many 'back-off-and-retry' attempts to find what characters it should and should not include in the match to that ".*" subpattern. The number of matching retries varies directly with the length of the 'tail' of the input string (that part not to be matched to ".*"), and geometrically with the number of ".*" subpatterns. Under worst-case conditions, only a few of these multiple-".*" subpatterns can have a discernible effect on the performance of a busy server.

For your query string, a negative match on ampersand or a numeric-only alternate character group would be much better, e.g.


RewriteCond %{QUERY_STRING} ^SubCat=([^&]+)&fd=([0-9]+)$
RewriteRule ^products/ProdBySubCat\.aspx$ http://new.example.com/ProdBySubCat-SubCat-%1-fd-%2.htm [R=301,L]

Jim