使用.htaccess从重定向中的查询字符串隔离ID
我有这段代码,可以使用.htaccess文件将URL的“?”部分更改为“/” 旧URL示例:使用.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
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?感谢您提高了问题的参考价值,使其更易于回答!