我制作了静态AMPhtml文件,我想稍后用WordPress连接。
我的结构是:
/amp/index.html
/amp/subpages.html
我已经尝试了很长时间了,而且我的工作方式从未发挥作用。
在根目录的.htaccess中我有:
# BEGIN Static AMP
RewriteEngine On
RewriteRule ^index\.html$ / [R,L,NC]
RewriteRule ^(.*)\.html$ /$1 [R,L]
# END Static AMP
# BEGIN Security
<files wp-config.php>
order allow,deny
deny from all
</files>
Options -Indexes
<files ~ "^.*\.([Hh][Tt][Aa])">
order allow,deny
deny from all
satisfy all
</files>
# END Security
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress
#-----------------------------------------------------------------#
# NOTE: #
# When testing your .htaccess do not use 301 redirects. #
# Use 302 until finished testing, as the browser will cache 301s. #
#-----------------------------------------------------------------#
#-----------------------------------------------------------------------------#
# FLAGS: #
# [R] redirect, by default 302, can use [R=301] #
# [NC] flag causes the RewriteRule to be matched in a case-insensitive manner #
# [L] flag causes mod_rewrite to stop processing the rule set. #
#-----------------------------------------------------------------------------#
我想要做的是重写
http://www.example.com/amp/index.html 至 http://www.example.com/amp/
和
http://www.example.com/amp/subpages.html 至 http://www.example.com/amp/subpages
有什么建议吗?
答案 0 :(得分:0)
回答我自己的问题。
# BEGIN Static AMP
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteRule ^amp/index\.html$ /amp [R,L,NC]
# example.com/page will display the contents of example.com/page.html
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}.html -f
RewriteRule ^(.+)$ $1.html [L,QSA]
# 301 from example.com/page.html to example.com/page
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /.*\.html\ HTTP/
RewriteRule ^(.*)\.html$ /$1 [R=301]
RewriteRule ^amp/index$ /amp [R=301,L]
</IfModule>
# END Static AMP
# BEGIN Security
<files wp-config.php>
order allow,deny
deny from all
</files>
Options -Indexes
<files ~ "^.*\.([Hh][Tt][Aa])">
order allow,deny
deny from all
satisfy all
</files>
# END Security
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress
#-----------------------------------------------------------------#
# NOTE: #
# When testing your .htaccess do not use 301 redirects. #
# Use 302 until finished testing, as the browser will cache 301s. #
#-----------------------------------------------------------------#
#-----------------------------------------------------------------------------#
# FLAGS: #
# [R] redirect, by default 302, can use [R=301] #
# [NC] flag causes the RewriteRule to be matched in a case-insensitive manner #
# [L] flag causes mod_rewrite to stop processing the rule set. #
#-----------------------------------------------------------------------------#
#-------------------------------------------------------#
# This checks for existing folders (-d) and files (-f): #
# RewriteCond %{REQUEST_FILENAME} !-d #
# RewriteCond %{REQUEST_FILENAME} !-f #
#-------------------------------------------------------#
#-------------------------#
# .HTACCESS Testing Tool #
# http://htaccess.mwl.be/ #
#-------------------------#
&#13;