Gha*_*man 3 php regex wordpress .htaccess mod-rewrite
我必须提供一些有关我的网站环境的信息
我的根目录中有静态网页。
WordPress 安装在子词典 www.domain.com/blog/ 中
我有两个 .htaccess ,一个在根目录中,一个在 wordpress 文件夹中。
我想要
一些例子
域名.tld/index.html >> 域名.tld/
域名.tld/file.html >> 域名.tld/file/
域名.tld/file.html/ >> 域名.tld/file/
域名.tld/wordpress/post-name >> 域名.tld/wordpress/post-name/
我在 ROOT htaccess 中的代码是
<IfModule mod_rewrite.c>
Options +FollowSymLinks -MultiViews
RewriteEngine On
RewriteBase /
#removing trailing slash
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)/$ $1 [R=301,L]
#www to non
RewriteCond %{HTTP_HOST} ^www\.(([a-z0-9_]+\.)?domain\.com)$ [NC]
RewriteRule .? http://%1%{REQUEST_URI} [R=301,L]
#html
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^\.]+)$ $1.html [NC,L]
#index redirect
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /index\.html\ HTTP/
RewriteRule ^index\.html$ http://domain.com/ [R=301,L]
RewriteCond %{THE_REQUEST} \.html
RewriteRule ^(.*)\.html$ /$1 [R=301,L]
</IfModule>
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteBase /blog/
# Force Trailing Slash for wordpress
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)[^/]{1}$ %{REQUEST_URI}/ [L,R=301]
</IfModule>
Run Code Online (Sandbox Code Playgroud)
上面的代码做了
#removing trailing slash Rule usage
Run Code Online (Sandbox Code Playgroud)
对于站点根 .htaccess 来说是这样的:
<IfModule mod_rewrite.c>
Options +FollowSymLinks -MultiViews
RewriteEngine On
RewriteBase /
#www to non
RewriteCond %{HTTP_HOST} ^www\.(([a-z0-9_]+\.)?domain\.com)$ [NC]
RewriteRule ^(.+?)/?$ http://%1/$1/ [R=301,L]
RewriteCond %{THE_REQUEST} \s/+(.+?)\.html/?[\s?] [NC]
RewriteRule ^ /%1/ [R=301,NE,L]
#index redirect
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /index\.html\ HTTP/
RewriteRule ^index\.html$ http://%{HTTP_HOST}/ [R=301,L]
# add a trailing slash to non files
RewriteCond %{ENV:REDIRECT_STATUS} ^$
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*?[^/])$ %{REQUEST_URI}/ [L,R=301,NE]
# add html internally
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^.]+)/$ $1.html [L]
</IfModule>
Run Code Online (Sandbox Code Playgroud)
确保在测试之前清除浏览器缓存。
| 归档时间: |
|
| 查看次数: |
13967 次 |
| 最近记录: |