繁体   English   中英

为特定目录添加斜杠(Slim框架)

[英]Add trailing slash for specific directory (Slim framework)

我要实现的目标:

www.mydomain/app => www.mydomain/app/ 

仅用于此URL。

我正在使用Slim Framework,这是我处理路线的方式:

$app->get('/', function () use ($app){
    // Some code goes here
});

我尝试过的

1)这些结果:

$app->get('/?', function () use ($app){
    // Some code goes here
});

$app->get('(/)', function () use ($app){
    // Some code goes here
});

2)这个效果很好,但打破了我的其他路线:

RewriteCond $0 !^app(/|$)
RewriteRule ^[^\.]+[^/]$ /$0/ [R=301,L]

例如我有路线

www.mydomain.com/app/panel 

在上面的规则之后,我将重定向到

www.mydomain.com/panel/

3)这个也可以,但是为每个网址添加了斜杠:

# Add a trailing slash to any non-existent files
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_URI} !(.*)/$
RewriteRule ^(.*)$ %{REQUEST_URI}/ [R=301,L]

4)这将我重定向到www.mydomain.com/

RewriteCond %{REQUEST_URI} ^/(app|foo|bar)$
RewriteRule ^(.*)$ http://%{HTTP_HOST}/$1/ [R=301,L]

感谢您提供的可能对我有帮助的指导或参考。

更新:

我的根目录.htaccess:

AddHandler php53 .php
Action php53 /cgi-bin/php53.cgi


DirectoryIndex index.php
<ifModule mod_gzip.c>
  mod_gzip_on Yes
  mod_gzip_dechunk Yes
  mod_gzip_item_include file \.(html?|txt|css|js|php|pl)$
  mod_gzip_item_include handler ^cgi-script$
  mod_gzip_item_include mime ^text/.*
  mod_gzip_item_include mime ^application/x-javascript.*
  mod_gzip_item_exclude mime ^image/.*
  mod_gzip_item_exclude rspheader ^Content-Encoding:.*gzip.*
</ifModule>
RewriteEngine on

#RewriteCond   %{REMOTE_HOST}  !^192\..*
#RewriteRule   ^(.*)         http://www.randomurl.com/$1 [R,L]



RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?rqp=$1 [L,QSA]
php_flag last_modified 1
php_flag register_globals 0
php_flag display_errors 1
php_flag magic_quotes_gpc 1

php_flag error_reporting E_ALL

AddDefaultCharset utf-8

#AddType  text/html .d

AddHandler application/x-httpd-php .dll

我的应用程序目录.htaccess:

RewriteEngine On

RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [QSA,L]

如果您只想要这个www.mydomain/app => www.mydomain/app/

然后,您可以在DOCUMENT_ROOT/.htacces添加以下行:

DirectorySlash On

作为根.htaccess的第一行

暂无
暂无

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

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