搜尋

首頁  >  問答  >  主體

url中增加一個目錄結構,.htaccess檔301重定向規則怎麼寫?

我的是wordpress的網站,想改版

固定連結從 http://網域/%post_id%.html 跳到  http://網域/�tegory%//%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

AddDefault

RewriteCond %{REQUEST_METHOD} !POST

RewriteCond %{QUERY_STRING} !.*=.*

RewriteCond %{HTTP:Cookie} !^.*(comment_author_#RewriteCond %{HTTP:Cookie} !^.*(comment_author_|wordpress_logged_in|word| 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_

##RewriteCond %{HTTP:Cookie} !^.*(comment_

## |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} !-f

RewriteCond %{REQUEST_FILENAME} !-d##} !-d

重寫規則。 /index.php [L]


## 結束 WordPress

# 開始 EWWWWIO

## 結束EWWWIO


#######
大海潮涌大海潮涌2612 天前1440

全部回覆(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
  • 取消回覆