Jetserver – The Lazy Admin Blog
Home  /  Apache • cPanel  /  Redirecting .aspx to PHP

Redirecting .aspx to PHP

elialum February 09, 2017 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

About Author

elialum

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
Search in posts
Search in pages
Filter by Categories
Apache
CentOS
CloudLinux
cPanel
ESXI
iSCSI
JetBackup
Litespeed
MySQL
NGINX
Reduxio
SSL
Uncategorized
VMware
Wordpress
XEN

Tags

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

Popular Posts

  • How To Install & Configure a Galera Cluster with MySQL on Centos 7 February 6, 2018
  • Allow a cPanel server to run a VHOST from multiple IP addresses April 3, 2018
  • Libmodsecurity installation April 14, 2016
  • JetBackup Cheat Sheet :: Automatically Acknowledge Alerts November 15, 2018

Recent Posts

  • Dealing with aggressive bot scanners September 14, 2020
  • Litespeed Geo Location Redirect September 14, 2020
  • JetBackup :: Restore on steroids ! August 21, 2020
  • XENSERVER :: CONNECTING ISCSI SR NETAPP STORAGE September 4, 2019

Recent Comments

  • Khan on Allow a cPanel server to run a VHOST from multiple IP addresses
  • Khan on Allow a cPanel server to run a VHOST from multiple IP addresses
  • Oleg Drabkin on Allow a cPanel server to run a VHOST from multiple IP addresses
  • Khan on Allow a cPanel server to run a VHOST from multiple IP addresses
  • Daniel on How To Install & Configure a Galera Cluster with MySQL on Centos 7
אחסון אתרים | JetApps