Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/266.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
mod_重写问题与php_Php_Apache_.htaccess_Mod Rewrite - Fatal编程技术网

mod_重写问题与php

mod_重写问题与php,php,apache,.htaccess,mod-rewrite,Php,Apache,.htaccess,Mod Rewrite,我正在尝试转换我的应用程序链接,以便像这样的链接: http://localhost/index.php?id=13&category=Uncategorized&title=just-a-link 转换为以下格式: http://localhost/13/Uncategorized/just-a-test 到目前为止,我能够通过以下方式完成: RewriteEngine On RewriteRule ^([^/]*)/([^/]*)/([^/]*)$ /index.php?

我正在尝试转换我的应用程序链接,以便像这样的链接:

http://localhost/index.php?id=13&category=Uncategorized&title=just-a-link
转换为以下格式:

http://localhost/13/Uncategorized/just-a-test
到目前为止,我能够通过以下方式完成:

RewriteEngine On
RewriteRule ^([^/]*)/([^/]*)/([^/]*)$ /index.php?id=$1&category=$2&title=$3 [QSA,L]
但这完全破坏了到css和其他文件的链接,因为它使用查询将每个请求重定向到index.php

因此,我对其进行了轻微更改,使其仅在第一个查询为数字时运行:

RewriteEngine On
RewriteRule ^([0-9]*)/([^/]*)/([^/]*)$ /index.php?id=$1&category=$2&title=$3 [QSA,L]
这个不会破坏css和js文件,但是,当您转到链接时,例如
http://localhost/13/cat/test
然后尝试转到另一个链接,如
http://localhost/19/Uncategorized/something
在上一页中单击它,它会将您重定向到类似的位置
http://localhost/13/Uncategorized/19/Uncategorized/just-a-test

我如何在没有这些奇怪副作用的情况下实现我所描述的呢???

使用:

RewriteEngine On
RewriteRule ^([0-9]+)/([^/.]+)/([^/.]+)/?$ /index.php?id=$1&category=$2&title=$3 [QSA,L]
并将此代码添加到您的
html




修复相关css和js链接

效果不错!但是有没有什么方法可以跳过html部分而获得相同的结果呢?没有,因为您更改了包含的所有链接的相对路径。但你也只能使用绝对链接。。。或者在
/A/B/C/
文件夹中使用
index.php
。。。
<base href="/">
<base href="http://www.domain.com/">