【发布时间】:2017-09-04 07:26:51
【问题描述】:
我目前有我的作品集要处理,我希望启用 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>
我得到的错误如下:
必须在“section”标签上指定“type”属性。 (...\web.config 第 7 行)
必须在“section”标签上指定“type”属性。 (...\web.config 第 8 行)
【问题讨论】:
-
您的意思是要链接到,例如,yoursite.com/work,而不是让常规链接指向那里,而是链接到 yoursite.com /index.html 然后使用javascript从索引加载适当的页面?这是真的,你为什么要这样做?
-
我的意思是启用重新路由,所以在 url 栏中输入 name.com/page 然后它将转到该页面。我的 index.html 开始将 url 中的页面加载到站点中。所以我不希望 name.com/page 转到 name.com/index.html,而是将其屏蔽为 /page,如果这有意义的话。
-
您的意思是,您只有一个页面而不是多个页面(索引、工作、关于...),但您想让其他 URL 指向相应的部分页面,对吗?在这种情况下,为什么不简单地使用 yoursite.com/#work?
-
有点像。基本上该网站有多个 html 页面。它就像一块磁铁板。如果你去/工作,它会从板上取下磁铁并在上面放置一个不同的磁铁。它永远不会离开 index.html,但它里面的内容会被切换。如果你想看看它是如何运作的,去the site here
-
请不要破坏您的问题。
标签: javascript html apache .htaccess