Solved

Htaccess url redirect change asp to php and pass url params

Posted on 2008-06-18
5
813 Views
Last Modified: 2012-08-13
Here is what I want to do. goes to template.asp?TemplateID=## I want them to get redirected to template.php?aid=##

This is what I want to put into my htaccess file will the last 2 strings work?

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{QUERY_STRING} ^TemplateID=([0-9])$
RewriteRule template\.asp template\.php\?aid=%1/? [R=301]
0
Comment
Question by:debugitbob
  • 2
  • 2
5 Comments
 
LVL 20

Accepted Solution

by:
virmaior earned 250 total points
ID: 21814041
well, the first of those two lines will only work if it is only one digit

RewriteCond %{QUERY_STRING} ^TemplateID=([0-9])$

change to:

RewriteCond %{QUERY_STRING} ^TemplateID=([0-9]*)$

change the last one to:

RewriteRule template\.asp?TemplateID=([0-9]*) template\.php\?aid=%1/? [R=301]
0
 
LVL 3

Author Comment

by:debugitbob
ID: 21816449
it doesn't seem to work. The site was migrated from ASP to PHP and it moved servers to a non IIS server. so all the old links from Google point to the old asp pages. I want to redirect to the PHP versions, I made a place holder asp page to redirect but because the server is non IIS it just shows the html code. so I put the redirect info into the .htaccess and the only line working there is a ErrorDocument 404 redirect I have.

Here is the full file

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{QUERY_STRING} ^TemplateID=([0-9]*)$
RewriteRule template\.asp?TemplateID=([0-9]*) redirect\.php\?aid=%1/? [R=301]
ErrorDocument 404 http://www.dentalcomfortzone.com/inthenews.php
0
 
LVL 3

Author Comment

by:debugitbob
ID: 21816465
so what I want is when someone goes to dentalcomfortzone.com//template.asp?TemplateID=88 I want them to get redirected to dentalcomfortzone.com/template.php?aid=88
0
 
LVL 20

Expert Comment

by:virmaior
ID: 21816511
try this for the last line:
RewriteRule template\.asp\?TemplateID=([0-9]*) redirect.php?aid=%1 [R=301]

also check  your log to see if one of the lines is considered broken.

0
 
LVL 51

Expert Comment

by:ahoffmann
ID: 21820977
> .. will the last 2 strings work?
no

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{QUERY_STRING} ^TemplateID=([0-9]*)$
RewriteRule template\.asp template.php?aid=%1 [R=301]

If you want to have the query string also, you need to add the QSA flag.
Keep in mind that this rule matches template.asp anywhere in the path.
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Things That Drive Us Nuts Have you noticed the use of the reCaptcha feature at EE and other web sites?  It wants you to read and retype something that looks like this.Insanity!  It's not EE's fault - that's just the way reCaptcha works.  But it is …
If your site has a few sections that need to be secure when data is transmitted between the server and local computer, such as a /order/ section for ordering or /customer/ which contains customer data, etc it would of course be recommended to secure…
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…

863 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

25 Experts available now in Live!

Get 1:1 Help Now