开发者

How to rewrite .aspx to .html or .php with htaccess

开发者 https://www.devze.com 2023-02-21 18:22 出处:网络
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

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.


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


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消