如果您在Apache网络服务器托管,在同一文件夹内容创建以下.htaccess
文件:
<IfModule mod_rewrite.c>
# Enable rewrite engine
RewriteEngine on
# If the condition "file does not exist"…
RewriteCond %{REQUEST_FILENAME} !-f
# or the condition "directory does not exist"…
RewriteCond %{REQUEST_FILENAME} !-d
# rewrite the request as if it came from index.php
RewriteRule^index.php [L]
</IfModule>
对于IIS服务器,请尝试以下web.config
文件:
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<system.webServer>
<rewrite>
<rules>
<!-- Rewrite URLs of the form 'x' to the form 'index.php?q=x'. -->
<rule name="Short URLs" 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" />
</conditions>
<action type="Rewrite" url="index.php?q={R:1}" appendQueryString="true" />
</rule>
</rules>
</rewrite>
<httpErrors>
<remove statusCode="404" subStatusCode="-1" />
<error statusCode="404" prefixLanguageFilePath="" path="/index.php" responseMode="ExecuteURL" />
</httpErrors>
<defaultDocument>
<!-- Set the default document -->
<files>
<remove value="index.php" />
<add value="index.php" />
</files>
</defaultDocument>
</system.webServer>
</configuration>
两种配置松散地基于Drupal 7配置文件。他们将所有请求到Web服务器不匹配实际的文件或目录(例如/约-US)实际上返回从index.php
不是输出(你可以把index.html
那里,而不是您投放静态HTML文件) 。这一切都发生在服务器端...最终用户仍然可以看到他们输入的URL(http://yourdomain.com/about-us)。您可以使用JavaScript捕获该URL(如location.href
),并执行您需要做的任何显示更改。
看看'location.hash' –
你托管的网站的Apache Web服务器上?如果你愿意,'.htaccess'重写可能是答案。 – thirdender
我正在使用IIS7 – user541597