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
Linux
Litespeed
MySQL
NGINX
Oracle
Reduxio
Security
SSL
Uncategorized
VMware
Wordpress
XEN

Tags

apache aspx backup bash 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 ssmtp systemd threads VMFS WHM Wordpress xenserver

Popular Posts

  • Convert JetBackup to cPanel structure October 6, 2022
  • 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
  • rsync without prompting for password October 10, 2022

Recent Posts

  • Understanding Why More Threads Can Sometimes Slow Down Performance October 9, 2024
  • Set up a new systemd service May 18, 2024
  • Bash Arrays November 7, 2023
  • rsync without prompting for password October 10, 2022

Recent Comments

  • Sven on rsync without prompting for password
  • TheLazyAdmin on rsync without prompting for password
  • Sven on rsync without prompting for password
  • TheLazyAdmin on Convert JetBackup to cPanel structure
  • Chris on Convert JetBackup to cPanel structure
Privacy Policy • Contact