1

What I want to achieve:

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

Only for this url.

I'm using Slim Framework and this is how I handle my route:

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

What I've tried:

1) Any results with these:

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

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

2) This one works great but brokes my other routes:

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

For example I got route

www.mydomain.com/app/panel 

after rules above it redirects me to

www.mydomain.com/panel/

3) This one also works but it adds slashes for every url:

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

4) This one redirects me to www.mydomain.com/

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

Thank you for any guidance or references that might help me.

UPDATE:

My root directory .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

My app directory .htaccess:

RewriteEngine On

RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [QSA,L]
anubhava
  • 761,203
  • 64
  • 569
  • 643
mintaras
  • 301
  • 3
  • 11

1 Answers1

1

If all you want is this www.mydomain/app => www.mydomain/app/

Then you can just add this line in your DOCUMENT_ROOT/.htacces:

DirectorySlash On

as the first line in your root .htaccess

anubhava
  • 761,203
  • 64
  • 569
  • 643
  • Works for www.mydomain/app => www.mydomain/app/. But I get 404 on www.mydomain/app/panel. – mintaras Dec 16 '13 at 12:41
  • As you can see that pattern `^(app)$` won't match `/app/panel` hence it won't cause 404. Does `/app/panel` work without this rule? – anubhava Dec 16 '13 at 12:43
  • In order other urls to work properly these rules are defined: **RewriteEngine On RewriteCond %{REQUEST_FILENAME} !-f RewriteRule ^ index.php [QSA,L] ** But then your rule stops working. – mintaras Dec 16 '13 at 13:05
  • Your rule goes first as you said. Still doesn't work. .htaccess file is located inside app directory and it is only one in it. Though one more .htaccess is located at parent directory (root) => www.mydomain.com/ – mintaras Dec 16 '13 at 13:16
  • Oh Ok in that case my suggested rule goes as **first rule in parent directory of `app`** – anubhava Dec 16 '13 at 13:20
  • Now I got 400 Bad Request for => www.mydomain/app. Everything else works good. – mintaras Dec 16 '13 at 13:34
  • Is app a real directory? – anubhava Dec 16 '13 at 13:35
  • Yes. 'app' is a real directory. Directory contains index.php with my app code. – mintaras Dec 16 '13 at 13:45
  • ok check the update and make sure it is in the parent .htaccess of app – anubhava Dec 16 '13 at 13:48
  • If I add 'DirectorySlash On' in my root .htaccess on every page including main page (www.mydomain.com) I'm getting 500 error – mintaras Dec 16 '13 at 14:00
  • Hmm `DirectorySlash` must always be `On` for security reasons also. Why it is giving 500 error to you difficult to guess. Can you check your Apache error.log for the reason of this error. Also it would help immensely if you post both root .htaccess and `/app/.htaccess` in your question. – anubhava Dec 16 '13 at 14:02
  • Please see the UPDATE. Meanwhile I'll look for apache error logs. – mintaras Dec 16 '13 at 14:15
  • 1
    Ok add this line `RewriteCond %{REQUEST_FILENAME} !-d` below `RewriteCond %{REQUEST_FILENAME} !-f` in your `app/.htaccess` and retest. – anubhava Dec 16 '13 at 14:22
  • You're welcome, glad it worked. Just a request about your future question to provide as much details about your current rules and current setup upfront to get best possible answers. – anubhava Dec 16 '13 at 14:53