我创建了自己的 cms,但发现以下问题。页面链接显示如下:
https://www.example.com/page/contact-us
我希望它们显示为这样,通过删除 page 别名:
https://www.example.com/contact-us
我的 Htaccess:
Options -MultiViews RewriteEngine On RewriteRule ^page/([\s\S]*)$ single-page.php?slug=$1 [L]
我已经尝试过,但对我不起作用
RewriteEngine On RewriteRule ^([^/]*)$ /page/single-page.php?slug=$1 [L]
最佳答案
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]
关于php - 如何使用 htaccess 从 url 中删除页面别名?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/64828323/