我正在尝试使用 htaccess 重写一些链接

我正在尝试使用 htaccess 重写一些链接

我有几个 URL,需要将它们重写为下面的 URL:

http://domain.net/blog/posts
http://domain.net/blog/posts/index
http://domain.net/blog/posts/view/uri/non-working-holiday
http://domain.net/blog/posts/view/uri/we-no-longer-offer
http://domain.net/blog/posts/view/uri/festivals
http://domain.net/blog/posts/view/uri/christmas-is-just-around-the-corner

http://domain.net/posts/
http://domain.net/posts/index
http://domain.net/posts/view/uri/non-working-holiday
http://domain.net/posts/view/uri/we-no-longer-offer
http://domain.net/posts/view/uri/festivals
http://domain.net/posts/view/uri/christmas-is-just-around-the-corner

我希望我的 .htaccess 可以修复此问题,但是没有:

Options +FollowSymLinks
IndexIgnore */*
RewriteEngine on

RewriteRule ^blog\/(.*)$ posts\/$1  [NC]

# if a directory or a file exists, use it directly
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d

# otherwise forward it to index.php
RewriteRule . index.php

答案1

Options +FollowSymLinks
IndexIgnore */*
RewriteEngine on

RewriteRule ^blog/(.*)$ /posts/$1  [R=301,L]

# if a directory or a file exists, use it directly
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
# otherwise forward it to index.php
RewriteRule ^(.*)$ index.php [QSA,L]

相关内容