Replace .php with .asp for all urls (inc subdomains)

28 Views Asked by At

I tried to find a solution and used the search here, but unfortunately all the variants I could find did not work in my case. I need your help please. For example, I have a site.com and subdomains (wildcard). All pages have a .php extension. How can I change the .php extension to .asp for all pages in the browser? For example when I open sub.site.com/page.php page in the browser I need it to look like sub.site.com/page.asp Please note, all subdomains are located in subdirectories. This is an example of a line from site.com.conf file VirtualDocumentRoot /var/www/site.com/public_html/%1/

This is my current .htaccess file but it doesn't work:

RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} ^www\.(.*)$ [NC]
RewriteRule ^(.*)$ https://%1/$1 [R=301,L]

RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.php -f
RewriteRule ^(.*)\.asp$ $1.php [L]

I have tried different options for .htassess - but none of the options work.

I also tried this option, but it doesn't work either:

RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} ^www\.(.*)$ [NC]
RewriteRule ^(.*)$ https://%1/$1 [R=301,L]

RewriteEngine On
RewriteBase /

RewriteCond %{HTTP_HOST} ^(.+)\.site\.com$ [NC]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.php -f
RewriteRule ^(.*)\.asp$ $1.php [L]
0

There are 0 best solutions below