.htaccess htaccess |将全部重定向到主目录下的模板
我需要访问所有被重定向到模板文件中的目录(或包含)的地址。例如:.htaccess htaccess |将全部重定向到主目录下的模板,.htaccess,templates,mod-rewrite,.htaccess,Templates,Mod Rewrite,我需要访问所有被重定向到模板文件中的目录(或包含)的地址。例如: /sports/basketball/ ==> /template_sport.php?idsport=$1 /sports/soccer/ ==> /template_sport.php?idsport=$1 /sports/tennis/ ==> /template_sport.php?idsport=$1 但是,如果我们访问/sports/(无子目录)来加载该目录中的页面,则会出现这种情况 我受够了。。。
/sports/basketball/ ==> /template_sport.php?idsport=$1
/sports/soccer/ ==> /template_sport.php?idsport=$1
/sports/tennis/ ==> /template_sport.php?idsport=$1
但是,如果我们访问/sports/(无子目录)来加载该目录中的页面,则会出现这种情况
我受够了。。。子目录,运行良好,但当我访问/sports/时,我也尝试访问/plantilla_-exporte.php
RewriteCond %{REQUEST_URI} sports/(.*)
RewriteRule (.*) /template_sport.php?idsport=$1
如果您直接转到/运动/找不到模板,我如何添加例外
提前谢谢 您可以尝试以下方法:
RewriteEngine on
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} ^/sports/([^/]+)
RewriteRule .* http://example.com/sports/template_sport.php?idsport=%1 [L]
它将以静默方式映射所有URL,如下所示:
http://example.com/sports/basketball
致:
http://example.com/sports/template_sport.php?idsport=basketball
当传入URL为以下内容时,它将不起任何作用:
http://example.com/sports/
好的!太完美了。。。然后我可以使用$\u SERVER['REQUEST\u URI']获取IDSport,但是如果我想使用$\u get['IDSport']获取de IDSport???我尝试放置?idsport=$1,但参数不是send。。。在您的示例中,发送“xx”mmm。。谢谢,但是,请不要继续发送任何内容。。。。$\u GET['id']的结果是无效的:(但别担心…它对我有效…我可以用$\u服务器['REQUEST\u URI']获取IDSport…它可以执行任何str\u替换,我得到我的有效结果…谢谢X 1000!!:)根据您的问题,它不应该是IDSport
?