2

I'm trying to rewrite some URLs that have a .aspx extension to .html. I looked around and saw that you can put something like

RewriteEngine On  
RewriteCond %{QUERY_STRING} ^file=(.+)$  
RewriteRule ^(.+)\.aspx$ $1.php?f=%1  

in the htaccess to rewrite any .aspx to .php. However, when I put that in the .htaccess file, it doesn't seem to work for me. mod_rewrite is enabled and the site is on a Linux server so those are not the issue. If I try to go anywhere with a .aspx extension, I get a "Server Error in '/' Application." error.

You can see this by going here http://www.netstar.co.uk.php5-20.websitetestlink.com/about-us.aspx. Any help for this would be greatly appreciated...it has been a thorn in my side for quite some time.

Rup
  • 33,765
  • 9
  • 83
  • 112
zhumar
  • 21
  • 1
  • 3
  • so you want .html in the url and on your server the file is .aspx? – Tobias Mar 31 '11 at 14:05
  • There will be no .aspx files on the server. We're just making a new site for our client in a linux environment so we needed their old URLs to be rewritten to work with Joomla. The main purpose is to do 301 redirects so we don't break any of their SEO. – zhumar Apr 01 '11 at 17:27

2 Answers2

1

You say that the site is on a linux server and mod_rewrite is enabled.

However, when I navigate to the link you provided, I get the following HTTP response headers:

Cache-Control   private
Content-Type    text/html; charset=utf-8
Server  Microsoft-IIS/7.0
X-AspNet-Version    2.0.50727
X-Powered-By    ASP.NET
Date    Thu, 31 Mar 2011 15:24:33 GMT
Content-Length  1508

Which tells me that no, it's not a Linux server, no it isn't running Apache, and no it doesn't have mod_rewrite enabled.

But I'm not surprised by any of this, because you're writing aspx code, which would normally not be run on a linux/apache server anyway.

I suggest you investigate the IIS equivalent of mod_rewrite. Try starting at this question here on SO: mod_rewrite equivalent for IIS 7.0

Community
  • 1
  • 1
Spudley
  • 166,037
  • 39
  • 233
  • 307
  • 1
    Also the error message "Server Error in '/' Application." is the error message ASP.NET returns. And considering the Server is obviously IIS, it ain't Mono he's running. :) – adamjford Mar 31 '11 at 15:51
  • That's weird. The site is on the Rackspace Cloud and it should be using their linux environment. Maybe this is something I should bring up with them then. We're switching to a purely linux host soon so maybe that will help clear this issue up. Thanks for pointing this out! – zhumar Apr 01 '11 at 17:25
0

My usual mistake: you need to enable .htaccess files in httpd.conf (or, on e.g. Ubuntu, in your site configuration file). In the main <Directory> block (or is it <Location>?) there's probably a directive that ignores .htaccess files in the root directory, or in all directories.

It's probably easiest to just add your rewrite rules to the root <Directory> instead. Remember to restart apache after changing these files.

Rup
  • 33,765
  • 9
  • 83
  • 112