Solved

Htaccess url redirect change asp to php and pass url params

Posted on 2008-06-18
5
820 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
[X]
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
  • 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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

If you are a web developer, you would be aware of the <iframe> tag in HTML. The <iframe> stands for inline frame and is used to embed another document within the current HTML document. The embedded document could be even another website.
Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
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 …

733 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