【问题标题】:How to remove the page alias from url with htaccess?如何使用 htaccess 从 url 中删除页面别名?
【发布时间】:2021-02-25 21:34:15
【问题描述】:

我创建了自己的 cms,但发现以下问题。页面链接显示如下:

https://www.example.com/page/contact-us

我希望它们显示为这样,通过删除 page 别名:

https://www.example.com/contact-us

我的 Htaccess:

选项 - 多视图 重写引擎开启 RewriteRule ^page/([\s\S]*)$ single-page.php?slug=$1 [L]

我试过了,但对我不起作用

重写引擎开启 重写规则 ^([^/]*)$ /page/single-page.php?slug=$1 [L]

【问题讨论】:

    标签: php apache .htaccess mod-rewrite


    【解决方案1】:
    RewriteRule ^([^/]*)$ /page/single-page.php?slug=$1 [L]
    

    这不起作用,因为它将所有 URI 转发到 /page/ 目录,而这显然不存在。

    你应该使用这条规则:

    # If the request is not for a valid directory
    RewriteCond %{REQUEST_FILENAME} !-d
    # If the request is not for a valid file
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteRule ^([^/]+)/?$ single-page.php?slug=$1 [L,QSA]
    

    【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2020-05-11
    • 1970-01-01
    • 1970-01-01
    • 2013-09-29
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多