簡體   English   中英

如何使用.htaccess 從 url 中刪除頁面別名?

[英]How to remove the page alias from url with htaccess?

我創建了自己的 cms,但發現了以下問題。 頁面鏈接顯示如下:

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

我希望他們通過刪除頁面別名來顯示:

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

我的訪問權限:

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]

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM