Htaccess 重定向似乎不适用于 seo 友好(无扩展名)url 的 php 文件扩展名
P粉724737511
P粉724737511 2023-09-13 11:37:25
0
1
572

我网站的一个旧网址结构如下:

https://example.com/login.php or, https://example.com/login.php?redirect=https://example.com or, https://example.com/register.php

重建 URL 后,URL 如下所示:

https://example.com/login or, https://example.com/login?redirect=https://example.com or, https://example.com/register

现在,当用户/访问者使用旧 URLhttps://example.com/login.php时,我想重定向到https://example.com/login页面。我该怎么做?

仅供参考,目前,我的.htaccess文件具有以下内容:

AddDefaultCharset UTF-8 ErrorDocument 404 /error-404/ ## Options +FollowSymlinks -MultiViews RewriteEngine on RewriteBase / ## Allow a few SEO Files direct access. RewriteRule ^robots.txt?$ robots.txt [L] RewriteRule ^ads.txt?$ ads.txt [L] RewriteRule ^sellers.json?$ sellers.json [L] ## Avoid rewriting rules for the admin section RewriteRule ^(admin|resources)($|/) - [L] ## Set Ajax Request File RewriteRule ^kahuk-ajax.php?$ kahuk-ajax.php? [L,QSA] ## Set controller with id RewriteRule ^([^/]+)/([0-9]+)/?$ index.php?con=&id= [L,QSA] ## Set controller with slug RewriteRule ^([^/]+)/([^/]+)/?$ index.php?con=&slug= [L,QSA] ## For paging RewriteRule ^([^/]+)/page/([0-9]+)/?$ index.php?con=&page= [L,QSA] RewriteRule ^([^/]+)/([^/]+)/page/([0-9]+)/?$ index.php?con=&slug=&page= [L,QSA] ## Set controller for only one parameter RewriteRule ^page/([^/]+)/?$ index.php?con=page&slug= [L,QSA] RewriteRule ^([^/]+)/?$ index.php?con= [L,QSA] ## Set home page RewriteRule ^/?$ index.php?con=home [L]

P粉724737511
P粉724737511

全部回复 (1)
P粉464208937

您可以在RewriteBase /行下方插入此规则来删除.php扩展名:

# To externally redirect /afile.php to /afile RewriteCond %{THE_REQUEST} \s/+(.+?)\.php[\s?] [NC] RewriteRule !^admin/ /%1 [R=301,NE,L,NC]
    最新下载
    更多>
    网站特效
    网站源码
    网站素材
    前端模板
    关于我们 免责声明 Sitemap
    PHP中文网:公益在线PHP培训,帮助PHP学习者快速成长!