1

I was figuring out how to clean the URL for my Silex app being in a subdir of my apache server. This is the actual path: /domains/mydomain.com/public_html/silex with the following subdirs:

public_html/
    css/
    images/
    js/
    .htaccess
    index.php
src/
templates/
vendor/

So, if I go to: http://www.mydomain.com/silex/public_html/ I'll find my Silex app that is working properly, but in the URL you can see the public_html/ dir. I'd like to hide it somehow since that all my pages such as about/, contacts/, etc. will always contain that subdir in front of them.

How to avoid that?

Here's my .htaccess:

<IfModule mod_rewrite.c>
    Options -MultiViews

    RewriteEngine On
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteRule ^ index.php [QSA,L]
</IfModule>

Basically, I just would like that my URLs become like this:

http://www.mydomain.com/silex/about
http://www.mydomain.com/silex/contacts
http://www.mydomain.com/silex/admin
(etc...)

Instead of:

http://www.mydomain.com/silex/public_html/about
http://www.mydomain.com/silex/public_html/contacts
http://www.mydomain.com/silex/public_html/admin
(etc...)

Thanks very much to all! :)

Omnhio
  • 231
  • 1
  • 6

1 Answers1

1

Here are a couple options (you must put all of them in the .htaccess of the first public_html):

  1. Make a catch-all RewriteRule and use index.php to show different content RewriteRule ^silex\/(.*)$ silex/public_html/index.php?screen=$1 [NC] - With this one, you can then catch the variable in index.php with $_GET['screen'] and load any content you wish accordingly.
  2. Or you can make specific rules to redirect to specific pages RewriteRule ^silex\/about$ silex/public_html/about.php | RewriteRule ^silex\/contacts$ silex/public_html/contacts.html etc.

Let me know if you have any further questions.

SimpleAnecdote
  • 765
  • 9
  • 17