我有一个网页,如果用户输入不存在的文件或文件夹http://www.somewebsite.com/nonexistingfolder或http://www.somewebsite.com/nonexistingfile.html将只是简单地转发到 www .somewebsite.com。然后想创建一个从 www.somewebsite.com/about.html 到 www.somewebsite.com/about 的网页,因为我认为越短越好。使用.htaccess
我认为我可以RewriteCond
用于不存在的和RewriteRule
用户友好的网页 url。我在 .htaccess 方面很糟糕我只知道基础知识,我甚至对可能已经问过但不确定如何编写此异常规则的问题进行了研究。
如何添加代码.htaccess
以便我可以拥有除我指定的网页 url 之外的所有不存在的文件/文件夹?. 下面的这个将简单地将所有不存在的内容重定向到 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]