将/path/index.html更改为/ path / with nginx

时间:2015-03-12 10:07:12

标签: .htaccess mod-rewrite nginx

在我当前的lightspeed服务器中,我使用以下代码将/path/index.html用于/pathg//path/example.html/path/example/

# to make `/path/index.html` to /path/
RewriteCond %{THE_REQUEST} ^GET\s(.*/)index\.html [NC]
RewriteRule . %1 [NE,R=301,L]

RewriteCond %{THE_REQUEST} ^GET\s.+\.html [NC]
RewriteRule ^(.+)\.html$ /$1 [NE,R=301,L,NC]

RewriteCond %{REQUEST_URI} !\.html$ [NC]
RewriteCond %{REQUEST_FILENAME}.html -f
RewriteRule . %{REQUEST_URI}.html [L]

# to make `/path/index.php` to /path/
RewriteCond %{THE_REQUEST} ^GET\s(.*/)index\.php [NC]
RewriteRule . %1 [NE,R=301,L]

RewriteCond %{THE_REQUEST} ^GET\s.+\.php [NC]
RewriteRule ^(.+)\.php$ /$1 [NE,R=301,L,NC]

RewriteCond %{REQUEST_URI} !\.php$ [NC]
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule . %{REQUEST_URI}.php [L]

有没有人知道如何使用nginx实现相同的目标?

0 个答案:

没有答案