我试图重写我的网址,但没有按预期工作。此
RewriteRule ^([^/]*)/$ /index.php?currentpage=$1 [L]
should rewrite
http://site/index.php?currentpage=2 to-> http://site/2/
但是没有任何事情发生http://site/index.php?currentpage=2
。还有这个
RewriteRule ^([^/]*)/$ /page.php?pn=$1 [L]
should rewrite http://site/page.php?pn=2 to-> http://site/2/
此制动整个站点并导致错误500
知道为什么和出了什么问题?
答案 0 :(得分:1)
我已使用此类链接继续下一页或上一页
// Prev page
<a href='{$_SERVER['PHP_SELF']}?currentpage=$prevpage'>
// Next page
<a href='{$_SERVER['PHP_SELF']}?currentpage=$nextpage'>
我一开始并没有理解它并试图仅在.htaccess
文件中进行更改,但后来我发现如果我不改变就没有办法实现也hrefs
所以我就像这样改变它们
// Prev page
<a href='/currentpage/$prevpage/'>
// Next page
<a href='/currentpage/$nextpage/'>
在.htaccess
文件中我把这个
Options +FollowSymLinks
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^currentpage/([^/]*)/$ /index.php?currentpage=$1 [L]
现在当我更改页面时就像http:/website.com/currentpage/2/
如果有其他错误但是到目前为止按预期工作,请纠正我。感谢您的帮助!
<强>更新强>
我忘记了这一点,当我做出这些更改时,我也改变了我的style.css
和其他图片/ js等文件的路径。我的意思是在我过去以style.css
这种方式<link rel="stylesheet" type="text/css" href="include/style.css">
之后更改网址以获取正确的路径之前必须添加一个主斜杠(/)使其成为<link rel="stylesheet" type="text/css" href="/include/style.css">
之前。还添加到其他元素..