Solved

Htaccess url redirect change asp to php and pass url params

Posted on 2008-06-18
5
812 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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
> .. 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

Zoho SalesIQ

Hassle-free live chat software re-imagined for business growth. 2 users, always free.

Join & Write a Comment

Author Note: Since this E-E article was originally written, years ago, formal testing has come into common use in the world of PHP.  PHPUnit (http://en.wikipedia.org/wiki/PHPUnit) and similar technologies have enjoyed wide adoption, making it possib…
These days socially coordinated efforts have turned into a critical requirement for enterprises.
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…
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

744 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

10 Experts available now in Live!

Get 1:1 Help Now