.htaccess伪静态实际运用

广告位

自定义404页面 ErrorDocument 404 /404.php 将.php转换为.html RewriteEngine On RewriteRule ^index.html$ index.php [QSA,L] RewriteRule ^kr-severdetails.html$ kr-severdetails.php [QSA,L] QSA用于在URL中截取查询的字段,L为只要符合当前判断,立即停止。 当我访问index.html时,实际请求index.php的内容并返回参数。 将设置访问权限 <Files 403.shtml> order allow,deny allow from all </Files> RewriteRule list/([1-9]+[0-9]*).html$ list.php?pid=$1 [QSA] 原链接:http://www.xxx.com/list.php?pid=1 伪静态:http://www.xxx.com/list/1.html 控制PHP版本 # php — BEGIN cPanel-generated handler, do not edit # This domain inherits the “PHP” package. # php — END cPanel-generated handler,…

自定义404页面

ErrorDocument 404 /404.php

.php转换为.html

RewriteEngine On
RewriteRule ^index.html$ index.php [QSA,L]
RewriteRule ^kr-severdetails.html$ kr-severdetails.php [QSA,L]

QSA用于在URL中截取查询的字段,L为只要符合当前判断,立即停止。

当我访问index.html时,实际请求index.php的内容并返回参数。

将设置访问权限

<Files 403.shtml>
    order allow,deny
    allow from all
</Files>

RewriteRule list/([1-9]+[0-9]*).html$ list.php?pid=$1 [QSA]

原链接:http://www.xxx.com/list.php?pid=1

伪静态:http://www.xxx.com/list/1.html

控制PHP版本

# php -- BEGIN cPanel-generated handler, do not edit
# This domain inherits the “PHP” package.
# php -- END cPanel-generated handler, do not edit
AddHandler application/x-httpd-ea-php73 .php .php7 .phtml

通过判断是否符合规则的链接进行重定向:

RewriteCond %{HTTPS} off
RewriteCond %{HTTP:X-Forwarded-SSL} !on
RewriteCond %{HTTP_HOST} ^cn\.hostease\.com$ [OR]
RewriteCond %{HTTP_HOST} ^www\.cn\.hostease\.com$
RewriteRule ^/?$ "https\:\/\/cn\.hostease\.com\/" [R=302,L]

通过判断访问是否为80端口来进行重定向:

RewriteEngine On
RewriteCond %{SERVER_PORT} 80
RewriteRule ^(.*)$ https://www.domain.com/$1 [R,L]

通过判断如果是443以外的端口,一律进行重定向来进行重定向:

RewriteEngine on
RewriteBase /
RewriteCond %{SERVER_PORT} !^443$
RewriteRule ^.*$ https://%{SERVER_NAME}%{REQUEST_URI} [L,R]

判断子目录的重定向:

RewriteEngine On
RewriteCond %{SERVER_PORT} 80
RewriteCond %{REQUEST_URI} subfolder
RewriteRule ^(.*)$ https://www.domain.com/subfolder [R,L]

将以上代码复制到.htaccess中即可。

关于作者: Harrison K

为您推荐

广告位

Leave a Reply

Your email address will not be published. Required fields are marked *