0

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]
rhje
  • 7
  • 3
  • Why on searth would one want to do that? – arkascha Jun 29 '23 at 05:50
  • So what does "does not work" actually mean? Does the process crash? Do you get an error? Do you get a "wrong" result? – arkascha Jun 29 '23 at 05:51
  • The rewriting rules you posted indeed won't work. Look at your second condition: you only want to apply the actual rule if a request to something ending with ".asp" points to a file ending with ".php" if you append ".php" to what is requested. But are your actual file names really ending in ".asp.php"? – arkascha Jun 29 '23 at 05:54
  • @arkascha File Extensions is .php. NOT ".asp.php". – rhje Jun 29 '23 at 14:21
  • Yes, I would expect that. But that condition you implemented tests for a file with the file ending ".asp.php". Which is why your rule never gets applied. – arkascha Jun 29 '23 at 20:09
  • @arkascha do you know how to fix this? – rhje Jun 30 '23 at 21:36

0 Answers0