使用.htaccess更改URL子域 /永久链接的一部分而不会引起404



我正在使用WordPress,我有这样的URL:

domain.com/my-pages/The+Title/go/

我要删除" go",而my-pages更改为书籍,例如:

domain.com/books/The+Title

而不会引起404错误。

我使用自定义插件时不可能通过永久链接。

我已经在.htaccess中尝试过,但它不起作用:

RewriteEngine on
RewriteCond %{HTTP_HOST} ^www.domain.com$ [NC]
RewriteRule ^(.*)$ http://domain.com/$1 [R=301,L]
RewriteRule ^my-pages/([^.]+)/go/$ books/$1 [L]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ /index.php/$1 [L]

有什么想法?

iirc在 .htaccess中时,路径以斜杠(" /")开头,因此当您将正则表达式锚定在字符串的开头(" ^"符号):

RewriteRule ^/my-pages/([^.]+)/go/$ books/$1 [L]
             ^
              `-- missing in your case

您可以用RewriteBase apache docs 来控制它,请参见:

  • RewriteBase如何在.htaccess中工作(Stackoverflow Q& a,Apr 2009)

最新更新