Php 使用htaccess创建漂亮的URL

Php 使用htaccess创建漂亮的URL,php,.htaccess,href,Php,.htaccess,Href,我想缩短此URL:'http://localhost/school/readmore?id=2“(必须用引号括起来,因此不允许发布本地主机URL)。我已经这样做了http://localhost/school/readmore-2.html'使用此.htaccess文件: RewriteEngine On IndexIgnore * RewriteCond %{SCRIPT_FILENAME} !-d RewriteCond %{SCRIPT_FILENAME} !-f RewriteRul

我想缩短此URL:'http://localhost/school/readmore?id=2“(必须用引号括起来,因此不允许发布本地主机URL)。我已经这样做了http://localhost/school/readmore-2.html'使用此
.htaccess
文件:

RewriteEngine On
IndexIgnore *

RewriteCond %{SCRIPT_FILENAME} !-d
RewriteCond %{SCRIPT_FILENAME} !-f

RewriteRule ^readmore-([1-9]+).html$ readmore.php?id=$1
这是修改后的链接

<a href="readmore-<?php echo $show_row['id']; ?>.html">Readmore</a>

但我希望URL看起来像这样http://localhost/school/readmore/2'. 我试过一次,但完全失败了;以下是不起作用的脚本:

RewriteEngine On
IndexIgnore *

RewriteCond %{SCRIPT_FILENAME} !-d
RewriteCond %{SCRIPT_FILENAME} !-f

RewriteRule ^readmore/([1-9]+).html$ readmore.php?id=$1

<a href="readmore/<?php echo $show_row['id']; ?>.html">Readmore</a>
重新编写引擎打开
IndexIgnore*
重写cond%{SCRIPT_FILENAME}-D
重写cond%{SCRIPT_FILENAME}-F
重写规则^readmore/([1-9]+).html$readmore.php?id=$1

起初我认为它可以工作,但CSS脚本没有加载,因为我在链接中将“
-
”更改为“
/
”,脚本将其作为文件夹读取。

退出您的

RewriteRule ^readmore/([1-9]+)\.html$ readmore.php?id=$1

您的浏览器认为它位于子目录中,因此它引用了'http://localhost/school/readmore/style.css“而不是”http://localhost/school/style.css"

要解决这个问题,您应该为样式表和链接使用绝对路径,例如

<link rel="stylesheet" href="http://localhost/school/style.css" />



当然
^readmore/([1-9]+).html$
在指定
.html
后缀时不会影响CSS文档。。。我想问你一件事:)。。。当我直接阅读更多页面时。。。我所有的链接都变了。。示例:“”对“”的更改不应发生。你只是在匹配和重写那些以readmore开头,以.html结尾的代码。。。我做错什么了吗?将其更改为,
/readmore/.html
<link rel="stylesheet" href="/school/style.css" />