我目前有我的作品集需要处理,并且我希望启用 hayofriese.com/work 等链接。在我的本地主机上,这是通过使用 .htaccess 文件解决的,一切运行顺利,但我托管网站的服务器不允许或不支持 htaccess 文件。
我该如何去做这项工作?
我的代码的工作方式是所有内容都重定向到index.html。每当有子链接(如/about 或/work)时,javascript 就会检测到并加载适当的页面。我只需启用重新路由,因为现在当我有 hayofriese.com/about 时,我收到 404 错误,这意味着尽管存在 localhost-working .htaccess 文件,但它不会重定向到 index.html。
任何帮助将不胜感激!
<configSections>
<sectionGroup name="system.webServer">
<sectionGroup name="rewrite">
<section name="rewriteMaps" overrideModeDefault="Allow" />
<section name="rules" overrideModeDefault="Allow" />
</sectionGroup>
</sectionGroup>
</configSections>
<system.webServer>
<security>
<requestFiltering>
<denyUrlSequences>
<add sequence="engine" />
<add sequence="inc" />
<add sequence="info" />
<add sequence="module" />
<add sequence="profile" />
<add sequence="po" />
<add sequence="sh" />
<add sequence="theme" />
<add sequence="tpl(\.html" />
<add sequence="Root" />
<add sequence="Tag" />
<add sequence="Template" />
<add sequence="Repository" />
<add sequence="code-style" />
</denyUrlSequences>
<fileExtensions>
<add fileExtension=".sql" allowed="false" />
<add fileExtension=".pl" allowed="false" />
</fileExtensions>
</requestFiltering>
</security>
<directoryBrowse enabled="true" />
<caching>
<profiles>
<add extension=".php" policy="DisableCache" kernelCachePolicy="DisableCache" />
<add extension=".html" policy="CacheForTimePeriod" kernelCachePolicy="CacheForTimePeriod" duration="14:00:00:00" />
</profiles>
</caching>
<rewrite>
<rules>
<rule name="Imported Rule 1" stopProcessing="true">
<match url="^(.*)$" ignoreCase="false" />
<conditions>
<add input="{HTTP_HOST}" pattern="^hayofriese\.com$" />
</conditions>
<action type="Redirect" redirectType="Permanent" url="http://www.hayofriese.com/{R:1}" />
</rule>
<rule name="Imported Rule 2" stopProcessing="true">
<match url="^(.*)$" ignoreCase="false" />
<conditions>
<add input="{REQUEST_FILENAME}" matchType="IsFile" ignoreCase="false" negate="true" />
<add input="{REQUEST_FILENAME}" matchType="IsDirectory" ignoreCase="false" negate="true" />
<add input="{URL}" pattern="^/favicon.ico$" ignoreCase="false" negate="true" />
</conditions>
<action type="Rewrite" url="index.html?q={R:1}" appendQueryString="true" />
</rule>
</rules>
</rewrite>
<defaultDocument>
<files>
<remove value="index.html" />
<add value="index.html" />
</files>
</defaultDocument>
<httpErrors>
<remove statusCode="404" subStatusCode="-1" />
<error statusCode="404" prefixLanguageFilePath="" path="/index.html" responseMode="ExecuteURL" />
</httpErrors>
</system.webServer>
我得到的错误如下:
The 'type' attribute must be specified on the 'section' tag. (...\web.config line 7)
The 'type' attribute must be specified on the 'section' tag. (...\web.config line 8)
最佳答案
由于您使用 .htaccess
我想在您的本地主机安装上使用 WAMP/Apache,但您的网站托管在 IIS 上运行的服务器中(Microsoft-IIS/7.5,如headers),它使用另一个文件进行目录配置。
您有两个选择:
如果可能,请将您的主机计划更改为使用 Apache 的另一个主机计划(如果您出于某种原因不需要 Linux 主机,一些主机提供商在 Windows 上提供 Apache)。在我看来,这将是使您的测试环境尽可能与网站服务器相似的最佳选择。
使用
web.config
,它或多或少相当于 IIS 中的.htaccess
,请查看此链接:
关于javascript - 如何为基于 html 和 javascript 的网站创建干净的 url,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46026447/