搜索

首页  >  问答  >  正文

url中增加一个目录结构,.htaccess文件301重定向规则怎么写?

我的是wordpress的网站,想改版

固定链接从 http://域名/%post_id%.html 跳转到  http://域名/%category%//%post_id%.html 

这个应该怎么写.htaccess文件301重定向规则呢?

以下是目前的htaccess文件:

# BEGIN WPSuperCache

<IfModule mod_rewrite.c>

RewriteEngine On

RewriteBase /

#If you serve pages from behind a proxy you may want to change 'RewriteCond %{HTTPS} on' to something more sensible

AddDefaultCharset UTF-8

RewriteCond %{REQUEST_METHOD} !POST

RewriteCond %{QUERY_STRING} !.*=.*

RewriteCond %{HTTP:Cookie} !^.*(comment_author_|wordpress_logged_in|wp-postpass_).*$

RewriteCond %{HTTP:X-Wap-Profile} !^[a-z0-9\"]+ [NC]

RewriteCond %{HTTP:Profile} !^[a-z0-9\"]+ [NC]

RewriteCond %{HTTP:Accept-Encoding} gzip

RewriteCond %{HTTPS} on

RewriteCond %{DOCUMENT_ROOT}/wp-content/cache/supercache/%{SERVER_NAME}/$1/index-https.html.gz -f

RewriteRule ^(.*) "/wp-content/cache/supercache/%{SERVER_NAME}/$1/index-https.html.gz" [L]


RewriteCond %{REQUEST_METHOD} !POST

RewriteCond %{QUERY_STRING} !.*=.*

RewriteCond %{HTTP:Cookie} !^.*(comment_author_|wordpress_logged_in|wp-postpass_).*$

RewriteCond %{HTTP:X-Wap-Profile} !^[a-z0-9\"]+ [NC]

RewriteCond %{HTTP:Profile} !^[a-z0-9\"]+ [NC]

RewriteCond %{HTTP:Accept-Encoding} gzip

RewriteCond %{HTTPS} !on

RewriteCond %{DOCUMENT_ROOT}/wp-content/cache/supercache/%{SERVER_NAME}/$1/index.html.gz -f

RewriteRule ^(.*) "/wp-content/cache/supercache/%{SERVER_NAME}/$1/index.html.gz" [L]


RewriteCond %{REQUEST_METHOD} !POST

RewriteCond %{QUERY_STRING} !.*=.*

RewriteCond %{HTTP:Cookie} !^.*(comment_author_|wordpress_logged_in|wp-postpass_).*$

RewriteCond %{HTTP:X-Wap-Profile} !^[a-z0-9\"]+ [NC]

RewriteCond %{HTTP:Profile} !^[a-z0-9\"]+ [NC]

RewriteCond %{HTTPS} on

RewriteCond %{DOCUMENT_ROOT}/wp-content/cache/supercache/%{SERVER_NAME}/$1/index-https.html -f

RewriteRule ^(.*) "/wp-content/cache/supercache/%{SERVER_NAME}/$1/index-https.html" [L]


RewriteCond %{REQUEST_METHOD} !POST

RewriteCond %{QUERY_STRING} !.*=.*

RewriteCond %{HTTP:Cookie} !^.*(comment_author_|wordpress_logged_in|wp-postpass_).*$

RewriteCond %{HTTP:X-Wap-Profile} !^[a-z0-9\"]+ [NC]

RewriteCond %{HTTP:Profile} !^[a-z0-9\"]+ [NC]

RewriteCond %{HTTPS} !on

RewriteCond %{DOCUMENT_ROOT}/wp-content/cache/supercache/%{SERVER_NAME}/$1/index.html -f

RewriteRule ^(.*) "/wp-content/cache/supercache/%{SERVER_NAME}/$1/index.html" [L]

</IfModule>


# END WPSuperCache


# BEGIN WordPress

<IfModule mod_rewrite.c>

RewriteEngine On

RewriteBase /

RewriteRule ^index\.php$ - [L]

RewriteCond %{REQUEST_FILENAME} !-f

RewriteCond %{REQUEST_FILENAME} !-d

重写规则。 /index.php [L]


# 结束 WordPress

## 开始 EWWWWIO

# EWWWIO 结束


大海潮涌大海潮涌2670 天前1490

全部回复(3)我来回复

  • 那山

    那山2017-09-20 08:15:00

     thinkphp

    回复
    0
  • PHP中文网

    PHP中文网2017-09-19 16:35:58

    建议使用php的301跳转

    Header("HTTP/1.1 301 Moved Permanently");
    Header("Location: http://www.php.cn".$_SERVER["REQUEST_URI"]);
    exit;


    回复
    0
  • 大海潮涌

    谢谢回答,不过目测不适用,我是要从从 http://域名/%post_id%.html 跳转到 http://域名/%category%/%post_id%.html ,批量的,中间增加目录名称。 比如:http://www.seoshipin.cn/1.html 跳转到 http://www.seoshipin.cn/seorumen/1.html

    大海潮涌 · 2017-09-19 18:55:27
  • 小小卫

    小小卫2017-09-19 16:11:26

    嗯嗯


    回复
    0
  • PHP中文网

    刷P豆的吧

    PHP中文网 · 2017-09-19 16:36:33
  • 取消回复