0
我想使用mod_rewrite只保留url中的查询字符串,并删除index.php?p =。.htaccess在URL中重写查询字符串
例如,这个链接
http://domain.com/index.php?p=page-name-with-dashes
进入
http://domain.com/page-name-with-dashes.html
所有网页都通过控制脚本的index.php和查询P =名字载入,这样
<?php
$page = isset($_GET['p']) ? $_GET['p'] : 'home';
...
require_once 'content-' . $page . '.php';
...
?>
我已经尝试了以下所有变体,但都没有工作 - 有些人给404一些给500错误。
#RewriteRule ^index.php?p=(.*) $1/
#RewriteRule ^([^/]+)/?$ /index.php?p=$1 [QSA,L]
#RewriteRule ^(.*)$ index.php?p=$1 [NC,L,QSA]
我在做什么错?我对htaccess规则不太了解,所以请原谅我的新手问题。
有一个小的修改,它的工作原理:RewriteRule ^(。*)。html $ index.php?p = $ 1 [L] –
我很抱歉,我刚从我上一个项目.htaccess文件复制了一行。并没有修改它,所以我现在编辑我的答案:) – Develoger