1

我需要将 /start 重定向到 /start/index.html 并将其他所有内容(/anything)重定向到 /index.html

什么是正确的正则表达式重写?

谢谢

4

2 回答 2

1

Rewrite condition is needed:

RewriteRule ^start/?$ /start/index.html [R]

RewriteCond %{REQUEST_URI} !^/start/?$
RewriteRule ^([a-zA-Z0-9_-]+)/?$ /index.html [R]

Please considered this link about the [R] flag: https://stackoverflow.com/a/15999177/2007055

于 2013-05-02T08:07:53.277 回答
1

我需要重定向/start/start/index.html和其他一切(/anything)到/index.html. 什么是正确的正则表达式重写?

您可以在根目录的一个 .htaccess 文件中尝试此操作:

Options +FollowSymlinks -MultiViews
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_URI}  !index\.html      [NC]
RewriteRule ^start/(.*)  /start/index.html?$1 [L,NC,QSA]

在规则中,anything作为查询传递给index.php,并且 QSA 标志在存在时添加传入的标志。

anything作为路径段传递,请替换?$1/$1删除 QSA 标志。这是没用的,因为任何传入的查询都会自动附加。

对于永久重定向,将 [L,NC,QSA] 替换为 [R=301,L,NC,QSA]

于 2013-05-02T09:26:49.107 回答