簡體   English   中英

如何更改我網站上的php URL?

[英]How to change php urls on my website?

是否可以通過以下方式更改我的網站鏈接:

domain.com/category.php?tag=test
domain.com/section.php?tag=test
domain.com/news.php?tag=test

到這個:

domain.com/category-test
domain.com/section-test
domain.com/news-test

謝謝,祝你有美好的一天!

您可以使用.htaccessmod_rewrite來實現。 您需要創建一個具有以下內容的.htaccess文件:

RewriteEngine On
RewriteBase /

RewriteRule ^category-([^/]+)/?$ category.php?tag=$1
RewriteRule ^section-([^/]+)/?$ section.php?tag=$1
RewriteRule ^news-([^/]+)/?$ news.php?tag=$1

現在,訪問domain.com/category-test/將帶您進入category.php?tag=test

如果您希望使用斜杠而不是破折號,則可以使用:

RewriteRule ^category/([^/]+)/?$ category.php?tag=$1
RewriteRule ^section/([^/]+)/?$ section.php?tag=$1
RewriteRule ^news/([^/]+)/?$ news.php?tag=$1
RewriteRule ^category-([a-zA-Z0-9]+)$ category.php?tag=$1 [NC,L]
RewriteRule ^section-([a-zA-Z0-9]+)$ section.php?tag=$1 [NC,L]
RewriteRule ^news-([a-zA-Z0-9]+)$ news.php?tag=$1 [NC,L]

在“ category.php”文件中,獲取標簽$ _GET ['tag'];

暫無
暫無

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

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