搜尋

首頁  >  問答  >  主體

Htaccess 重定向似乎不適用於 seo 友善(無副檔名)url 的 php 檔案副檔名

我網站的一個舊網址架構如下:

1

2

3

4

5

https://example.com/login.php

    or,

    https://example.com/login.php?redirect=https://example.com

    or,

    https://example.com/register.php

重建 URL 後,URL 如下所示:

1

2

3

4

5

https://example.com/login

    or,

    https://example.com/login?redirect=https://example.com

    or,

    https://example.com/register

現在,當使用者/訪客使用舊URL https://example.com/login.php# 時,我想重定向到https://example.com/login 頁面。我該怎麼做?

僅供參考,目前,我的 .htaccess 檔案具有以下內容:

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

32

33

34

35

36

37

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粉724737511P粉724737511549 天前732

全部回覆(1)我來回復

  • P粉464208937

    P粉4642089372023-09-14 09:29:25

    您可以在 RewriteBase / 行下方插入此規則來刪除 .php 副檔名:

    1

    2

    3

    # To externally redirect /afile.php to /afile

    RewriteCond %{THE_REQUEST} \s/+(.+?)\.php[\s?] [NC]

    RewriteRule !^admin/ /%1 [R=301,NE,L,NC]

    回覆
    0
  • 取消回覆