将web.config文件转换为.htaccess [英] Convert web.config file to .htaccess
本文介绍了将web.config文件转换为.htaccess的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在寻找一种将IIS重写规则转换为.htaccess文件的方法。我找不到任何自动执行此操作的工具,我只能得到500个内部服务器错误。
I'm looking for a way to convert my IIS rewrite rules to an .htaccess file. I couldn't find any tool to automatically do this and all I can get myself is 500 Internal Server Errors.
web.config文件如下所示:
The web.config file looks like this:
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<system.webServer>
<rewrite>
<rules>
<clear />
<rule name="RemoveTrailingSlash" stopProcessing="true">
<match url="^(.*?)/+$" />
<conditions logicalGrouping="MatchAll" trackAllCaptures="false">
<add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
<add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
</conditions>
<action type="Redirect" url="http://{HTTP_HOST}/{R:1}" />
</rule>
<rule name="HaltOnTinyMCE" stopProcessing="true">
<match url="^tinymce/.*$" />
<conditions logicalGrouping="MatchAll" trackAllCaptures="false" />
<action type="None" />
</rule>
<rule name="RewriteContent" enabled="true" stopProcessing="true">
<match url="^.*\.(gif|jpg|png|css|js|swf|txt|xml)$" />
<conditions logicalGrouping="MatchAll" trackAllCaptures="false" />
<action type="Rewrite" url="domains/{HTTP_HOST}/{R:0}" appendQueryString="true" logRewrittenUrl="false" />
</rule>
<rule name="RewritePages" enabled="true">
<match url="^.*$" ignoreCase="true" negate="false" />
<conditions logicalGrouping="MatchAll" trackAllCaptures="false" />
<action type="Rewrite" url="index.php" logRewrittenUrl="false" />
</rule>
</rules>
</rewrite>
</system.webServer>
</configuration>
我最好尝试手动转换它仍然给我500内部服务器错误。有什么建议吗?
My best try at manually converting this is still giving me the 500 Internal Server Error. Any suggestions?
RewriteEngine on
RewriteCond /+$
RewriteRule ^(.*?)/+$ http://{HTTP_HOST}/$1 [R=301,L]
RewriteCond ^tinymce/.*$
RewriteRule ^(.*)$ $1 [L]
RewriteCond \.(gif|jpg|png|css|js|swf|txt|xml)$
RewriteRule ^.*\.(gif|jpg|png|css|js|swf|txt|xml)$ domains/{HTTP_HOST}/$1 [L]
RewriteRule ^.*$ index.php
提前致谢!
推荐答案
你正走在右边方向,但有一些错误,和不需要的东西。这就是我提出的:
You were heading in the right direction, but there were a few errors, and unneeded things. This is what I came up with:
RewriteEngine on
RewriteBase /
#remove tailing slash
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)/$ http://%{HTTP_HOST}/$1 [R=301,L]
# stop rules below from being applied if url starts with tinymce/
RewriteRule ^tinymce/.*$ - [L]
#rewrite images etc. to domains folder (unless url already starts with domain/)
RewriteCond $0 !^domains/
RewriteRule ^.*\.(gif|jpg|png|css|js|swf|txt|xml)$ domains/%{HTTP_HOST}/$0 [L]
#catch all other (I added 2 rewriteconds, to prevent rewriting existing files (including index.php))
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^.*$ index.php
这篇关于将web.config文件转换为.htaccess的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文