Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

Htaccess url redirect change asp to php and pass url params

Posted on 2008-06-18
5
819 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

VMware Disaster Recovery and Data Protection

In this expert guide, you’ll learn about the components of a Modern Data Center. You will use cases for the value-added capabilities of Veeam®, including combining backup and replication for VMware disaster recovery and using replication for data center migration.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
AWS EC2 HTTP & HTTPS 2 44
Number of hours between date in DB and now 8 21
Split wordpress loop 35 56
What's wrong with this PDO query? 5 27
These days socially coordinated efforts have turned into a critical requirement for enterprises.
This article discusses four methods for overlaying images in a container on a web page
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 a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

808 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