我是htaccess和URL重写领域的初学者。帮我 我的代码:
www.example.com/education/education-centers.php
www.example.com/education/edu.php?Main=Colleges&Category=Engineering colleges
www.example.com/education/edu.php?Main=Colleges&Category=Engineering colleges&Start-page=1
www.example.com/education/edu.php?Main=Colleges&Category=Engineering colleges&DistrictName=Kannur
www.example.com/education/edu.php?Main=Colleges&Category=Engineering colleges&DistrictName=Kannur&start=1//used for pagination
www.example.com/education/edu.php?Main=Colleges&Category=Engineering colleges&DistrictName=Kannur&LocalityName=Taliparamba
www.example.com/education/edu.php?Main=Colleges&Category=Engineering colleges&DistrictName=Kannur&LocalityName=Taliparamba&start=1/used for pagination
www.example.com/education/education.php?Main=10&Id=12&Name=Sir Syed College Taliparamba
另外: 用于从我使用的子文件夹打印图像 www.example.com/education/subfolder/7.jpg 任何人都帮我纠正htaccess代码重写。 我的旧代码是这样的:
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^education-centers education-centers.php
RewriteRule ^(.*)/(.*)/(.*)/(.*)/([0-9]+)$ edu.php?Main=$1&Category=$2&DistrictName=$3&LocalityName=$4&start=$5 [L,NC,QSA]
RewriteRule ^(.*)/(.*)/(.*)/([0-9]+)$ edu.php?Main=$1&Category=$2&DistrictName=$3&start=$4 [L,NC,QSA]
RewriteRule ^(.*)/(.*)/(.*)/(.*)$ edu.php?Main=$1&Category=$2&DistrictName=$3&LocalityName=$4 [L,NC,QSA]
RewriteRule ^([0-9]+)/([0-9]+)/(.*)$ eduS.php?MainId=$1&Id=$2&Name=$3 [L,NC,QSA]
RewriteRule ^(.*)/(.*)/([0-9]+)$ edu.php?Main=$1&Category=$2&start=$3 [L,NC,QSA]
RewriteRule ^(.*)/(.*)/(.*)$ edu.php?Main=$1&Category=$2&DistrictName=$3 [L,NC,QSA]
RewriteRule ^(.*)/(.*)$ edu.php?Main=$1&Category=$2 [QSA,L]
但问题是图像没有打印.. Allways图像打印代码延伸到RewriteRule ^(.*)/(.*)$ edu.php?Main=$1&Category=$2 [QSA,L]
并显示错误。
任何人都可以建议我一个干净,准确的.htaccess代码。
答案 0 :(得分:1)
RewriteCond
仅适用于下一个RewriteRule
,因此您的规则会针对相同的URI多次触发。
试试这段代码:
RewriteEngine on
# skip all files and directories
RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^ - [L]
RewriteRule ^education-centers/?$ education-centers.php [L]
RewriteRule ^(.*)/(.*)/(.*)/(.*)/([0-9]+)$ edu.php?Main=$1&Category=$2&DistrictName=$3&LocalityName=$4&start=$5 [L,NC,QSA]
RewriteRule ^(.*)/(.*)/(.*)/([0-9]+)$ edu.php?Main=$1&Category=$2&DistrictName=$3&start=$4 [L,NC,QSA]
RewriteRule ^(.*)/(.*)/(.*)/(.*)$ edu.php?Main=$1&Category=$2&DistrictName=$3&LocalityName=$4 [L,NC,QSA]
RewriteRule ^([0-9]+)/([0-9]+)/(.*)$ eduS.php?MainId=$1&Id=$2&Name=$3 [L,NC,QSA]
RewriteRule ^(.*)/(.*)/([0-9]+)$ edu.php?Main=$1&Category=$2&start=$3 [L,NC,QSA]
RewriteRule ^(.*)/(.*)/(.*)$ edu.php?Main=$1&Category=$2&DistrictName=$3 [L,NC,QSA]
RewriteRule ^(.*)/([^/]*)$ edu.php?Main=$1&Category=$2 [QSA,L]