使用 .htaccess 重写 URL 以删除不需要的单词



>我需要重写网址所在的网址:

http://www.domainname.co.uk/blog/gallery/gallery2  --> URL1

哪些需要

http://www.domainname.co.uk/gallery/gallery2   ---> URL2

其中 http://www.domainname.co.uk/blog 是安装了WordPress的目录。现在,当我输入 URL2 时,它应该显示 URL1 的内容。可能吗?我只需要删除博客这个词。

-----------我的.htaccess---------

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
RewriteRule ^(gallery/.+)$ /blog/$1 [L,NC]
</IfModule>

已编辑
如果您在 htaccess 所在的根文件夹中使用 index.php,则可以按如下方式使用重写规则。

<IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteBase /
    RewriteRule ^index.php$ - [L]
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^(gallery/.+)$ /blog/$1 [L,NC]
    RewriteRule ^gallery$ http://www.domainname.co.uk/blog/gallery/1$ [L,P]
    RewriteRule . /index.php [L]
</IfModule>

相关内容

最新更新