Take the 2-minute tour ×
Webmasters Stack Exchange is a question and answer site for pro webmasters. It's 100% free, no registration required.

I've swapped from ASP.NET to .PHP for cost reasons. As such, I want the people to be redirected from .ASPX to its equivalent .PHP. If I create the .aspx with HTML, the file is simply displayed in the browser as text and not treated as text. How can I make the browser treat .aspx as HTML or is there another way to make APACHE redirect from aspx to its equivalent?

share|improve this question
    
Personally I would use URL rewrite rules, the other option is you need to go and tell apache to send it with the text/html or similar mime type in the headers. Either of these can be specified in apache config. –  ewanm89 Jul 8 '12 at 11:15

3 Answers 3

first, the browser does not care about the extension of the file name.

if in the response HTTP header you specify the content as text/html the browser will render the response as html. if you specify the response as text/plain the browser will just print the text.

what you should do is 2 things:

  1. use URL rewrite module to route requests for .aspx pages to .php pages.

  2. make sure you return 301 http status code, to tell search engines that the redirection is pernament.

share|improve this answer

YardenST is completely right it is your HTTP headers that are not telling your browser that the page is HTML and not a txt file.

But keep in mind what you are doing with .aspx is probably not the smartest thing in the world. Most web developers go out of their way to mask all file extensions (jsp, asp, shtml, php). If you are going to write rewrite rules, why not create one that actually hides the file extension so that: Default.aspx becomes Default. If you are trying to pretend that apache or whatever is serving your PHP files is IIS, dont. First its extremly easy to tell what server you are running on, and even if you changed the server headrers, its not worth the trouble.

Maybe you should just rename all your files to .php (so that if the application needs to be re-coded or edited your editor actually does the syntax highlighting for php and there is no confusion among devs), and then hide the .php extension, or write a rewrite rule that requests to .aspx are forwarded to .php.

share|improve this answer

I just had to do this today, I approached it the same way you would run php inside of html files. In my case I'm not worried about file extensions showing in the address bar, it's a copy of a client's Website he no longer has access to.

AddType application/x-httpd-php .aspx
AddHandler application/x-httpd-php .aspx

I hope that helps some.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.