繁体   English   中英

使用.htaccess的URL前缀

[英]URL prefix using .htaccess

我想使用htaccess文件为传入的URL加上前缀。 例如,URL可能是http://localhost/george_shop.html ,我希望htaccess像http://localhost/route/george_shop.html一样给它添加前缀

这是我现在的htaccess:

<IfModule mod_rewrite.c>
    RewriteEngine On

    RewriteCond %{REQUEST_FILENAME} -s [OR]
    RewriteCond %{REQUEST_FILENAME} -l [OR]
    RewriteCond %{REQUEST_FILENAME} -d
    RewriteRule ^.*$ - [NC,L]

    RewriteCond %{REQUEST_URI}::$1 ^(/.+)(.+)::\2$
    RewriteRule ^(.*) - [E=BASE:%1]
    RewriteRule ^(.*)$ %{ENV:BASE}index.php [NC,L]
</IfModule>

更新如果有帮助,这是Slim3 htaccess

我建议您使用苗条的regexp,这样可以动态地执行以下操作:

$app->get('/{route:.*(?:html)$}', function($req, $res, $args) {});

希望能帮助到你

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM