我想要达到的目标:
www.mydomain/app => www.mydomain/app/
仅适用于此网址。
我正在使用 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]