skip to Main Content

I’m trying to get right syntax for .htaccess without any result…

I’ve a URL structured as domain.com/app/public/pageName .

It’s working fine but I would “hide” the ‘app/public/’ part in browsers, basically doing something like:

[real URL] domain.com/app/public/pageName -> domain.com/pageName [what users type and see in browsers]

I think in that way it should be more readable and seo-friendly.

As I understood from docs (and maybe it’s wrong because it’s not working…) I should tell to Apache to map/redirect all URL like domain.com/pageName to domain.com/app/public/pageName , but only internally, in order to show the minimal URL in users’ browsers.

Right now I have something like:

RewriteEngine on

#RewriteBase /app/public/

RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f

RewriteRule ^(.+)$ https://localhost/app/public/index.php?url=$1 [QSA,L]

(I’m using full URL with https://… in order to get something that will be quick and easy to adapt when I upload all to my hosting, is it right?).

Problem is that RewriteRule actually change the URL, because it perform a redirect and URL rewrite it’s not handle internally.

So, first of all: is it possible what I’m trying to do? If so, how can I handle the URL rewrite only internally?

Everything should be uploaded to a shared hosting, so I don’t have other than .htaccess.
Anyway, I can consider to upgrade to a vps if there are not other possibilities…

Thanks!

==============

EDIT (should be more clear now)

tl;dr version:

I’m looking for a method that let users to type domain.com/pageName (and they will see that address in their browsers) and rewrite internally that URL in order to point to domain.com/app/public/pageName.

==============

More: after /app/public/ there can be an arbitrary number of elements, separated by / . All of these elements are appended at the end of the URL after index.php. At the end URL looks like:

  domain/app/public/index.php?url=lot/of/elements/here 

This is already working with the RewriteRule posted above, I would keep that too.
Thanks!

2

Answers


  1. This is working fine for me, Hope it will work for you as well.

    Check .htaccess here

    RewriteEngine on
    RewriteBase /
    RewriteCond %{REQUEST_URI} ^/app/public
    RewriteRule ^app/public/(.*)$ /$1 [L,QSA]
    
    Login or Signup to reply.
  2. Just for reference, I found a solution, maybe will be usefull for someone.

    Basically I moved .htaccess to the root server (instead of /app/public directory) and changed the RewriteRule as follow:

    RewriteEngine on
    RewriteBase /app/public/
    
    #RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_FILENAME} !-f
    
    RewriteRule ^(.*)$ index.php?url=$1 [PT]
    

    Now it’s working (at least on localhost).

    What do you think? Are there any side effects with this config?

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search