Forum Moderators: phranque

Message Too Old, No Replies

asp to php in .htaccess

         

vfetty

3:18 pm on Jan 9, 2008 (gmt 0)

10+ Year Member



Hello, If I have a directory that use to house all .asp files now I want to forward them to another directory. This is what I am trying but have not luck with it. Any clue to why? Thanks!

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteRule ^.asp$ /articles/index.php [R=301,L,QSA]
</IfModule>

PHP_Chimp

4:31 pm on Jan 9, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



At the moment you are not catching any pages, you need a () in there to catch something.

Try -
Assuming that you are redirecting from example.com/somepage.asp -> example.com/articles/index.php?somepage


RewriteEngine On
RewriteRule (.*)\.asp$ /articles/index.php?$1 [R=301,L]

Im not sure if that is what you want as (.*).asp is a file not a directory, neither is articles/index.php.
Also do you need the Query String Append (QSA)? Its because of that I am assuming you want to use the query string on the index.php page...dont know if that is what you actually want though.

When testing you may want to use a 302 redirect, as if you use a 301 to test then your browser will cache the results and keep giving you the same permanent redirection even once you change your .htaccess rules. Once you have finished testing then change it to the 301, so you get the permanent redirect.

jdMorgan

4:53 pm on Jan 9, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member




<IfModule mod_rewrite.c>
RewriteEngine On
RewriteRule ^.asp$ /articles/index.php [R=301,L,QSA]
</IfModule>

The specific problem is the "^" start-anchor on the regular expressions pattern. That pattern will match only a request for "example.com/.asp" and nothing else. Not likely that that is what was intended...

Jim

vfetty

5:14 pm on Jan 9, 2008 (gmt 0)

10+ Year Member



Thanks for all the helpful responses so far:) Is it then possible to grab the page that is being requested.

i.e. http://www.example.com/oldarticles/widget-design.asp

to then directed it to

http://www.example.com/newarticles/article-widget-design-page1.html

jdMorgan

5:26 pm on Jan 9, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I would question whether you actually want a redirect at all. Do you actually want to change the URLs (and lose the old page ranking and visitor bookmarks), or do you simply want to change the *files* that those URLs refer to? I believe that you might be happier with an internal rewrite (with the URLs remaining the same as they were, and only the files moving and/or changing).

You can rewrite or redirect anything to anything as long as the requested URL contains all of the information needed to construct the new URL or filepath. That is, mod_rewrite can re-arrange the requested URL-path, can add fixed values to it, can remove parts of it, or do some or all of these in combination. What it cannot do is 'create' new unique information from nothing.

See the discussion of "back references" in the RewriteCond and RewriteRule documentation.

Jim

vfetty

5:46 pm on Jan 9, 2008 (gmt 0)

10+ Year Member



I am starting to understand mod-rewrite a little more but this is to complex for me just yet. I have to loose the old rankings due to the fact that I moved to an article system and if I had to redirect from the old articles I would have to put in over 100+ files a redirect php statement in the file. That is why I thought someone might be able to lend me a hand with this. As 2 lines is a lot less work then modifying 100+ files.

So I guess is my previous post possible and is there any example someone can show me?

jdMorgan

7:43 pm on Jan 9, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



It's not necessary to change any of your php files based on your previous 'redirect' question.

Understand this: It is almost never a good thing to change a URL, and it is almost never necessary to change a URL. The only good reason to change a URL is because you are under a court order to change that URL -- for example, because you unknowingly violated someone's trademark.

Again, any URL can be mapped to any file on your server. You can move files into and out of subdiorectories, change from .cfm to .asp to .php, and never change a single link or URL on your site. If your site's filesstem and URL structure are well-organized, then this can be done very easily. If not, it may involve a rather long list of rewrite rules or a small script to do a translation database lookup, but it can almost always be done.

Here's a note from one of the two guys credited with inventing the hyperlinking concept that made the Web possible, Sir Tim Berners-Lee: Cool URIs don't change [w3.org].

I'd recommend that you take a step back from your plan, slow down, and take the time to learn what you actually need to do before committing to a plan which may give you cause to regret later.

Jim

g1smd

12:50 am on Jan 11, 2008 (gmt 0)

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



I have just looked at a site where they actually spent several weeks writing over 200 redirect rules, when all they needed was one simple AddType declaration, and about a dozen wildcarded internal rewrite rules

Their new site will be a lot harder to maintain, and risks breakage at some point in the future when the purpose of all the redirects is forgotten (or someone overwrites them).

vfetty

1:04 am on Jan 11, 2008 (gmt 0)

10+ Year Member



In this case I changed from ASP forum to PHP forum and could not do a one to one conversion. That would have been the way to go and your right forget 301 redirects they can get messy. Though with my forum it's went down in traffic, oh yes but will return as google is spidering away and it's an old and trusted site.