【发布时间】:2013-11-07 06:23:52
【问题描述】:
我有一个网页,如果用户 http://wwww.somewebsite.com/nonexistingfolder 或 http://www.somewebsite.com/nonexistingfile.html 键入不存在的文件或文件夹,则只需将其转发到 www.somewebsite.com。然后想创建一个从 www.somewebsite.com/about.html 到 www.somewebsite.com/about 的网页,因为我认为越短越好。使用.htaccess 我想我可以将RewriteCond 用于不存在的内容,将RewriteRule 用于用户友好的网页网址。我在 .htaccess 方面很糟糕我只知道基础知识,我甚至对可能已经提出的问题进行了研究,但不知道如何编写此例外规则。
如何在.htaccess 中添加代码,以便我可以拥有除我指定的网页网址之外的所有不存在的文件/文件夹?。下面的这个将简单地将所有不存在的内容重定向到 index.html,当我执行 www.somewebsite.com/about(来自 /about.html)时,只需转到 index.html。有什么帮助吗?
--- my .htaccess shows --
# Redirect non-existing files or folders to index
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ / [L,QSA]
</IfModule>
# Rewrite existing files sample RewriteRule ^contact/$ /pages/contact.htm [L]
RewriteEngine on
RewriteRule ^/$ index.html [L]
RewriteRule ^about/$ about.html [L]
RewriteRule ^services/$ services.html [L]
RewriteRule ^application/$ application.html [L]
RewriteRule ^contact/$ contact.html [L]
RewriteRule ^privacy/$ privacy.html [L]
【问题讨论】:
标签: .htaccess url-rewriting rewrite