如何使用 htaccess 将 .aspx 重写为 .html 或 .php
我正在尝试将一些扩展名为 .aspx 的 URL 重写为 .html。我环顾四周,发现您可以
RewriteEngine On
RewriteCond %{QUERY_STRING} ^file=(.+)$
RewriteRule ^(.+)\.aspx$ $1.php?f=%1
在 htaccess 中放置类似的内容,将任何 .aspx 重写为 .php。但是,当我将其放入 .htaccess 文件中时,它似乎对我不起作用。 mod_rewrite 已启用,并且该站点位于 Linux 服务器上,因此这些不是问题。如果我尝试访问带有 .aspx 扩展名的任何地方,我会收到“‘/’应用程序中的服务器错误”。错误。
您可以通过访问这里 http://www. netstar.co.uk.php5-20.websitetestlink.com/about-us.aspx。对此的任何帮助将不胜感激……相当长一段时间以来,它一直是我的眼中钉。
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您说该站点位于 Linux 服务器上并且启用了 mod_rewrite。
但是,当我导航到您提供的链接时,我收到以下 HTTP 响应标头:
这告诉我,不,它不是 Linux 服务器,不,它没有运行 Apache,不,它没有启用 mod_rewrite。
但我对此并不感到惊讶,因为您正在编写 aspx 代码,该代码通常不会在 linux/apache 服务器上运行。
我建议您研究 IIS 中相当于 mod_rewrite 的内容。尝试从这里开始解决这个问题: mod_rewrite 相当于 IIS 7.0
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:
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
我经常犯的错误是:您需要在 httpd.conf 中启用 .htaccess 文件(或者在 Ubuntu 上,在您的站点配置文件中)。在主
块中(或者是
?),可能有一个指令忽略根目录或所有目录中的 .htaccess 文件。最简单的方法可能是将重写规则添加到根
中。更改这些文件后请记住重新启动 apache。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.