问题描述
有关制作友好的URL,以下是应用htaccess的code:
RewriteEngine叙述在的RewriteCond%{} THE_REQUEST /.+?\\.php[\\s?] [NC]
重写规则^ - [F]重写规则^([^ / \\。] +)$的index.php?ID1 = $ 1 [NC,L,QSA]
重写规则^([^ / \\。] +)/([^ / \\。] +)$的index.php ID1 = $ 1和; ID2 = $ 16 [NC,L,QSA]
这现在工作为:
-
mydomain.com/pages
到mydomain.com/index.php?id1=pages
-
mydomain.com/pages/xyz
到mydomain.com/index.php?id1=pages&id2=xyz
此外,当我进入 mydomain.com/index.php?id1=pages&id2=xyz
在URL中手动,它重定向到 mydomain.com
。
现在,当我进入另一个像 mydomain.com/templates
,其中模板是存在的目录,它重定向到 mydomain.com/templates /?ID1 =模板
编辑1:
我想加入这一行,却徒劳无功:
的RewriteCond%{} REQUEST_FILENAME!-d
的RewriteCond%{DOCUMENT_ROOT} / $ 1 \\ .PHP -f [NC]
重写规则^(。+?)/ $ /$1.php [L]
我该如何避免这种情况(与该名称目录存在)使用htaccess的?
RewriteEngine叙述在的RewriteCond%{} THE_REQUEST /.+?\\.php[\\s?] [NC]
重写规则^ - [F]
#serve迪尔斯而无需重写
的RewriteCond%{} REQUEST_FILENAME -d
重写规则^ - [L]
#####
重写规则^([^ / \\。] +)$的index.php?ID1 = $ 1 [NC,L,QSA]
重写规则^([^ / \\。] +)/([^ / \\。] +)$的index.php ID1 = $ 1和; ID2 = $ 16 [NC,L,QSA]
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]
This now works for:
mydomain.com/pages
tomydomain.com/index.php?id1=pages
mydomain.com/pages/xyz
tomydomain.com/index.php?id1=pages&id2=xyz
also, when I enter mydomain.com/index.php?id1=pages&id2=xyz
manually in the URL, it redirects to mydomain.com
.
Now, when I enter another like mydomain.com/templates
where templates is a directory that exists, it redirects to mydomain.com/templates/?id1=templates
Edit 1:
I tried adding this line but in vain:
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{DOCUMENT_ROOT}/$1\.php -f [NC]
RewriteRule ^(.+?)/?$ /$1.php [L]
How shall I avoid this condition (when directory with that name exists) using htaccess?
RewriteEngine On
RewriteCond %{THE_REQUEST} /.+?\.php[\s?] [NC]
RewriteRule ^ - [F]
#serve dirs without rewriting
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^ - [L]
#####
RewriteRule ^([^/\.]+)$ index.php?id1=$1 [NC,L,QSA]
RewriteRule ^([^/\.]+)/([^/\.]+)$ index.php?id1=$1&id2=$2 [NC,L,QSA]
这篇关于当目录存在htaccess的重定向的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!