有关制作友好的URL,以下是应用htaccess的code:
For making friendly URLs, Following is the htaccess code applied:
RewriteEngine On RewriteCond %{THE_REQUEST} /.+?\.php[\s?] [NC] RewriteRule ^ - [F] RewriteRule ^([^/\.]+)$ index.php?id1=$1 [NC,L,QSA] RewriteRule ^([^/\.]+)/([^/\.]+)$ index.php?id1=$1&id2=$2 [NC,L,QSA]这现在工作为:
mydomain/pages 到 mydomain/index.php?id1=pages
mydomain/pages/xyz 到 mydomain/index.php?id1=pages&id2=xyz
此外,当我进入 mydomain/index.php?id1=pages&id2=xyz 在URL中手动,它重定向到 mydomain 。
also, when I enter mydomain/index.php?id1=pages&id2=xyz manually in the URL, it redirects to mydomain.
现在,当我进入另一个像 mydomain/templates ,其中模板是存在的目录,它重定向到 mydomain/templates /?ID1 =模板
Now, when I enter another like mydomain/templates where templates is a directory that exists, it redirects to mydomain/templates/?id1=templates
我试着加上几行,却徒劳无功:
I tried adding these lines but in vain:
RewriteCond %{REQUEST_FILENAME} !-d RewriteCond %{DOCUMENT_ROOT}/$1\.php -f [NC] RewriteRule ^(.+?)/?$ /$1.php [L]我的目录结构:
www/ .htaccess index.php <--- main router templates/ img/ css/ ... ... other_directories/ ... ...的index.php 应接受ID1和ID2。
index.php should receive id1 and id2.
我该如何避免这种情况(与该名称目录存在)使用htaccess的?
How shall I avoid this condition (when directory with that name exists) using htaccess?
注:这个问题已经在这里问 。但再次发布,因为它没有获得可观的意见,也没有回答这个问题!的
Note: This question is already asked here. But posting again, as it didn't gain considerable views nor answered the issue!
推荐答案您应该强制尾随斜线在使用重定向规则目录的前面:
You should force a trailing slash in front of directories using a redirect rule:
RewriteEngine On RewriteCond %{THE_REQUEST} /.+?\.php[\s?] [NC] RewriteRule ^ - [F] # add a trailing slash to directories RewriteCond %{REQUEST_FILENAME} -d RewriteRule ^(.*?[^/])$ %{REQUEST_URI}/ [L,R=302] RewriteRule ^([^/.]+)/?$ index.php?id1=$1 [L,QSA] RewriteRule ^([^/.]+)/([^/.]+)/?$ index.php?id1=$1&id2=$2 [L,QSA]更多推荐
htaccess的重定向失败时,目录中重定向
发布评论