The Lazy Admin Blog

Home  /  Apache • cPanel  /  Redirecting .aspx to PHP

Redirecting .aspx to PHP

February 09, 2017 Apache, cPanel Leave a Comment

In most cases 301 redirects are written in the “.htaccess” file. However, when the URL is complex and contains special characters it can be very tricky for the novice user.

To simplify the process we can redirect all the *.ASPX traffic to a PHP file, in which we will use a PHP script to perform the actual redirects.

First create an “.htaccess” file with a simple rewrite rule:

RewriteCond %{REQUEST_URI} (.*)\.aspx$
RewriteRule .* aspx_redirect.php [L]

Afterwards create the “aspx_redirect.php” file (which should be located in your public_html folder alongside the “.htaccess” file) and add the following code into it:

<?php
$get_url = $_SERVER['REQUEST_URI'];
$get_url = substr($get_url, 1);

$redirect_to = array(
      'Article.aspx?Item=626' => 'my-new-url',
);

if (isset($redirect_to[$get_url])) {
      header("Location: /{$redirect_to[$get_url]}", true, 301);
      exit;
} else {

      header("Location: /index.php", true, 301);
      exit;
}

?>

Old url: Article.aspx?Item=626
New url: my-new-url

* Note that we are not using “/” (forward slash) at the beginning of each URL.

Tags: aspx, php
Previous Article
Next Article

Leave a Reply

Cancel reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Search Our Blog

Generic selectors
Exact matches only
Search in title
Search in content
Post Type Selectors
Filter by Categories
Apache
CentOS
CloudLinux
cPanel
Emails
ESXI
iSCSI
JetBackup
Litespeed
MySQL
NGINX
Oracle
Reduxio
Security
SSL
Uncategorized
VMware
Wordpress
XEN

Tags

apache aspx backup CentOS cloudlinux cPanel CXS Emails freetds google htaccess IMAP InnoDB iscsi JetBackup Libmodsecurity litespeed modsec modsecurity mssql MySQL netapp nginx odbc Oracle php php.ini phpselector rsync ssh VMFS WHM Wordpress xenserver

Popular Posts

  • How To Install & Configure a Galera Cluster with MariaDB on Centos 7 February 6, 2018
  • Allow a cPanel server to run a VHOST from multiple IP addresses April 3, 2018
  • Convert JetBackup to cPanel structure October 6, 2022
  • Libmodsecurity installation April 14, 2016

Recent Posts

  • rsync without prompting for password October 10, 2022
  • Convert JetBackup to cPanel structure October 6, 2022
  • Configure LiteSpeed Crawler October 5, 2022
  • Change Hostname in Oracle Cloud Infrastructure (OCI) October 3, 2022

Recent Comments

  • Anonymous on Convert JetBackup to cPanel structure
  • TheLazyAdmin on How To Install & Configure a Galera Cluster with MariaDB on Centos 7
  • AO on How To Install & Configure a Galera Cluster with MariaDB on Centos 7
  • Javier Bastet on Convert JetBackup to cPanel structure
  • Anonymous on InnoDB: Failed to find tablespace for table `X` in the cache
Privacy Policy • Contact