AngularJS2 + Apache routing - apache

I'm currently using Angular2 with Apache and I have a problem: when I use routing and navigate through pages, template syntax doesn't work, I just get an empty space in the place where {{}} is in the template. Also ngOnInit seems to be not working. When I use lite-server everything works fine.
EDIT1: I'm trying to run an example from developer's guide on routing: https://angular.io/docs/ts/latest/guide/router.html
https://angular.io/resources/live-examples/router/ts/plnkr.html
EDIT2: I'm also using CodeIgniter 3 and it already uses the following .htaccess file:
RewriteEngine on
RewriteCond $1 !^(index\.php|resources|robots\.txt)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L,QSA]

It could be an issue with redirects/not-found files.
Try adding .htaccess file:
# BEGIN ServeStatic
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.html$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.html [L]
</IfModule>
# END ServeStatic

Related

Can we write .htaccess for two different dynamic pages like product.php & blog.php in php mysql?

Options +FollowSymlinks
RewriteEngine On
RewriteBase /
RewriteRule ^([^/]+)/?-([^/]+)? product-details.php?pro_slug=$1&id=$2 [L,QSA]
RewriteRule ^([^/]+)/?-([^/]+)? blog-details.php?n_slug=$1&n_id=$2 [L,QSA]
this will working for only first defined page product-details.php. please help.
I am hitting on www.test.com/blog/Want-to-transfer-your-home-loan-to-another-bank, www.test.com/product/agriculture-land-near-by-agra First url should be served by product-details and 2nd one should be served by blog-details.php file.
Based on your shown samples, please try following htaccess Rule file.
Make sure to clear your browser cache before testing your URLs.
Options +FollowSymlinks
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(blog)/([\w-]+)/?$ product-details.php?pro_slug=$1&id=$2 [NC,L,QSA]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(product)/([\w-]+)/?$ blog-details.php?n_slug=$1&n_id=$2 [NC,L,QSA]

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>
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]"
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>

Laravel on Plesk-Server - Only accessible by calling /public

When setting up a fresh Laravel installation, we have to run it using domain.com/public instead of domain.com.
I googled after this problem and I saw that this could be because of mod_rewrite not being enabled. However, we are running Plesk on our server and their documentation at http://download1.parallels.com/Plesk/PP12/12.0/Doc/en-US/online/plesk-administrator-guide/index.htm?fileName=74206.htm says:
The mod_rewrite module is enabled by default in Apache that comes with Plesk for Linux. To make use of the functionality, you will need to create an .htaccess file containing the desired rewrite rules - refer to the Apache documentation for more information.
Laravel is working fine, if I move the contents of public in the main folder, and the rest in a /laravel folder (simply have to adopt the main index.php file).
However I would like to keep the original file structure.
Any tips?
Just use .htaccess to redirect from / to /public. Maybe similar to this
RewriteCond %{REQUEST_URI} !^public
RewriteRule ^(.*)$ public/$1 [L]
You need two .htaccess files. One inside the Laravel Project and the other one inside your domain.com
Laravel Project (/var/www/vhosts/domain.com/public/.htaccess)
<IfModule mod_rewrite.c>
<IfModule mod_negotiation.c>
Options -MultiViews -Indexes
</IfModule>
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ public/index.php?$1 [L,QSA]
# Handle Authorization Header
RewriteCond %{HTTP:Authorization} .
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
# Redirect Trailing Slashes If Not A Folder...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} (.+)/$
RewriteRule ^ %1 [L,R=301]
# Send Requests To Front Controller...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
</IfModule>
main domain (/var/www/vhosts/domain.com/.htaccess)
RewriteEngine on
RewriteCond %{REQUEST_URI} !^public
RewriteRule ^(.*)$ public/$1 [L]

Apache rewrite empty regex (root)

I've got Apache 2.4.4 running on Windows 8 laptop (WAMP server) and I found a really odd behavior of .htaccess mod_rewrite rules.
I want to redirect the root of my website to a specific file. My .htaccess looks like this:
RewriteEngine On
RewriteBase /
RewriteRule $^ /static/home.php [L,QSA]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{DOCUMENT_ROOT}%{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{DOCUMENT_ROOT}%{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ router.php?url=$1 [L,QSA]
This works only if there's no index.php file in root directory. When I create index.php file, Apache redirects empty path straight to the index file and doesn't bother with the first RewriteRule.
Is there a way to have both these RewriteRules and index.php file working together? In oher words, my example works but I want to rename router.php to index.php and keep both RewriteRules working.
Thanks!
You can just tweak your regex pattern to work in both situation:
DirectoryIndex something-else.php
RewriteEngine On
RewriteRule ^$ /static/home.php [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?url=$1 [L,QSA]

.htaccess file is not working properly with slimphp framework

I am using Slim php framework, having no .htaccess file in root folder I can call the pages
like /index.php/pagename
but if I upload the following .htaccess file in the root folder I always get 403 Forbidden error like You don't have permission to access /hello on this server.
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . index.php [L]
</IfModule>
Try changing your rule to this:
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.+)$ index.php/$1 [L]
Then you can use a URI /hello which will be rewritten to /index.php/hello.
Please review the Route URL Rewriting
section of the Slim documentation. The .htaccess provided there is different than those posted here.
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [QSA,L]