.htaccess 如何使用htaccess呈现具有不同url的相同页面

.htaccess 如何使用htaccess呈现具有不同url的相同页面,.htaccess,url-rewriting,.htaccess,Url Rewriting,我有一个新域名,现在我想把所有的url都呈现到主页上 例如 此外,url将仅显示当前主页(index.html(或.php)),而不是 找不到,在此服务器上找不到请求的URL/index.php 我如何使用htaccess实现这一点 您可以在.htaccess中使用重写规则 RewriteEngine On RewriteRule ^.*$ index.php [NC,L] 这会将所有请求发送到index.php文件(或者您可以将其更改为index.htm等)您也可以绕过css/js等静态文件

我有一个新域名,现在我想把所有的url都呈现到主页上

例如

此外,url将仅显示当前主页(index.html(或.php)),而不是

找不到,在此服务器上找不到请求的URL/index.php


我如何使用htaccess实现这一点

您可以在.htaccess中使用重写规则

RewriteEngine On
RewriteRule ^.*$ index.php [NC,L]

这会将所有请求发送到index.php文件(或者您可以将其更改为index.htm等)

您也可以绕过css/js等静态文件:

RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]

首先,我缺少http服务器。它可能不是严格必要的(我不知道答案),但它可能需要回答这个问题。第二,关于“还将显示URL”,您的意思是希望将所有URI转发到index.html还是目前的情况?
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]