Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/url/2.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
使用.htaccess从重定向中的查询字符串隔离ID_.htaccess_Url - Fatal编程技术网

使用.htaccess从重定向中的查询字符串隔离ID

使用.htaccess从重定向中的查询字符串隔离ID,.htaccess,url,.htaccess,Url,我有这段代码,可以使用.htaccess文件将URL的“?”部分更改为“/” 旧URL示例:bithumor.co/posts?id=13 .htaccess重写后的新URL:bithumor.co/posts/13 代码如下: RewriteRule ^posts/([0-9]+)$ /posts/index.php?id=$1 [NC,L] 我做错了什么?如何修复此问题?尝试以下方法: RewriteEngine on RewriteCond %{REQUEST_FILE

我有这段代码,可以使用.htaccess文件将URL的“?”部分更改为“/”

旧URL示例:
bithumor.co/posts?id=13

.htaccess重写后的新URL:
bithumor.co/posts/13

代码如下:

RewriteRule    ^posts/([0-9]+)$    /posts/index.php?id=$1    [NC,L]
我做错了什么?如何修复此问题?

尝试以下方法:

RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f 
RewriteRule ^posts/([0-9]+)/?$    /posts/index.php?id=$1    [QSA,NC,L]
这些条件(RewriteCond)确保您不会重写服务器上的任何现有文件/目录。

请回答您的问题,确切地说,是什么让您认为出现了问题:您得到了什么URL以及应该改为什么URL?感谢您提高了问题的参考价值,使其更易于回答!