【发布时间】:2019-08-06 05:46:53
【问题描述】:
我想做一个这样的网址 如果参数只有一个 它将是来自 index.php?page=news
的 localhost/site/news这是.htaccess
RewriteEngine On
RewriteRule ^([a-zA-Z0-9_-]+)$ index.php?page=$1
RewriteRule ^([a-zA-Z0-9_-]+)/$ index.php?page=$1
但如果链接像这样 index.php?page=news&halaman=2
我想让它像这样 localhost/site/news/2
我试过了,但是没用
RewriteRule ^(.+?)/(.+?) index.php?p=$1&halaman=$2 [NC,L]
我该如何解决这个问题?谢谢...
【问题讨论】:
-
index.php?p=$1看起来你的参数被称为page,而不是p -
您应该将所有内容重定向到 index.php 并从那里进行路由。否则,每当添加新 URL 时,您都必须调整 htaccess。寻找 PHP 路由
-
好吧,我已将
p更改为page,但css 和js 很乱 -
查看这篇文章了解 CSS 和 JS 解决方案stackoverflow.com/questions/31241701/…
-
@LarsStegelitz OP 已经在寻求具有可变参数的通用解决方案。因此,他必须“在添加新 URL 时调整您的 htaccess”是不正确的。