Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How make htaccess for single-page app within a sub-path in URL?

I want to have a single-page app, but only within a sub URL like:

//The following would all be valid, but handled by the "index.html" 
//at http://www.test.com/webapp
http://www.test.com/webapp
http://www.test.com/webapp/settings
http://www.test.com/webapp/start

I want all the URLs to look exactly like above, but be handled by: http://www.test.com/webapp/index.html.

I also want the following URLs to not be handled by that page:

http://www.test.com
http://www.test.com/contact
http://www.test.com/about

How do I do this?

REGULAR SINGLE_PAGE HTACCESS

<ifModule mod_rewrite.c>
    RewriteEngine On
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule (.*) index.html [QA,L]
</ifModule>
like image 320
Don Rhummy Avatar asked Nov 19 '16 22:11

Don Rhummy


2 Answers

Just adding answer for reference.

The commnet from @Croises:

"The same (with [QSA] not [QA]) but in the webapp directory"

Worked for me.

The ".htaccess" must be on the subdieretory.

Example working ".htaccess":

<ifModule mod_rewrite.c>
    RewriteEngine On
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule (.*) index.html [QSA,L]
</ifModule>

The only diference is "[QA,L]" to "[QSA,L]"

like image 86
alex Avatar answered Oct 23 '22 22:10

alex


The answer marked as good didn't work for me. Below my solution:

1) Create .htaccess in the folder where you place your app
2) Paste the code below
3) Change folder_name to your folder name.

<IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteBase /folder_name/
    RewriteRule ^index\.html$ - [L]
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule . /folder_name/index.html [L]
</IfModule>
like image 33
user2811588 Avatar answered Oct 23 '22 20:10

user2811588