[英]How to change php urls on my website?
Is it possible to somehow change my website links from: 是否可以通过以下方式更改我的网站链接:
domain.com/category.php?tag=test
domain.com/section.php?tag=test
domain.com/news.php?tag=test
into this: 到这个:
domain.com/category-test
domain.com/section-test
domain.com/news-test
Thanks and have a good day! 谢谢,祝你有美好的一天!
You can achieve this using .htaccess
and mod_rewrite
. 您可以使用
.htaccess
和mod_rewrite
来实现。 You'll need to create a .htaccess
file with the following contents: 您需要创建一个具有以下内容的
.htaccess
文件:
RewriteEngine On
RewriteBase /
RewriteRule ^category-([^/]+)/?$ category.php?tag=$1
RewriteRule ^section-([^/]+)/?$ section.php?tag=$1
RewriteRule ^news-([^/]+)/?$ news.php?tag=$1
Now, accessing domain.com/category-test/
will take you to category.php?tag=test
. 现在,访问
domain.com/category-test/
将带您进入category.php?tag=test
。
If you'd prefer to have slashes instead of dashes, you can use: 如果您希望使用斜杠而不是破折号,则可以使用:
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]
In "category.php" file get the tag $_GET['tag']; 在“ category.php”文件中,获取标签$ _GET ['tag'];
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.