0

我有一个目录,其中列出了http://example.com/residencies/当您单击它链接到的住所时我们拥有的所有住所http://example.com/residencies/myhouse现在我需要 .htaccess 将地址重写为http://example.com/residencies/details.php?id=myhouse

我有

  RewriteCond %{QUERY_STRING} !(?:^|&)id= [NC]
  RewriteRule ^residencies/(.+)$ /residencies/details.php?id=$1 [QSA]

这将进行重定向,但也尝试重定向http://example.com/residencies/http://example.com/residencies/details.php?id= 给出错误的内容我如何使它忽略重写规则是否没有 id?

4

1 回答 1

0

我为有同样问题的人找到了我自己的问题的答案,我是如何解决的

# residencies rewrite
RewriteCond %{REQUEST_URI}  ^/residencies/$
RewriteRule ^(.*)$ /residencies/index.php [NC,L]

RewriteCond %{REQUEST_URI}  !^/residencies/$
RewriteCond %{REQUEST_FILENAME} !(index.php|details.php) [NC]
#RewriteCond %{QUERY_STRING} !id= [NC]
RewriteRule ^residencies/([^/]+)/?$ /residencies/details.php?id=$1 [NC,QSA,L]
于 2019-10-13T18:38:03.077 回答