I have an application and the entry point is index.php in /var/www/html/quote directory. The application is using slim framework to deliver json api. So I tested the application using php -S localhost:8080 but now I'm ready to upload to my hosting service so I want to be able to test the app by typing localhost/quote. I enabled mod_rewrite in apache2. Also I added this to the directory where index.php is localted
.htaccess file
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^ index.php [QSA,L]
finally, I modified the apache2.conf file and change directive like this. changing AllowOverride to All
<Directory /var/www>
Options Indexes FollowSymLinks
AllowOverride All
Require all granted
</Directory>
Now when I type http://localhost/quote. I'm getting "page not found"
what am I missing?
Related
I have an front-end application on apache server.
When i go to BASE URL it's fine but if go to (Base URL)/example and refresh this show the next message:
Not Found
The requested URL /example was not found on this server.
On my server linux (Centos 7) on /var/www/html have the ".htaccess" file with the next content:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.html$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.html [L]
</IfModule>
Somehelp how resolve this ?
Thank !
I have the next wrapper <Directory "/var/www/html"> Options Indexes FollowSymLinks AllowOverride None Require all granted </Directory>
It looks like .htaccess overrides are not enabled for the specific directory you have the .htaccess file.
It should be AllowOverride All in the <Directory "/var/www/html"> container.
Then restart Apache for the changes to take effect.
Switching from a GoDaddy shared server to my own home server (with multiple virtual websites)
On GoDaddy I used the .htacess below for 301 redirects and it worked fine. It was located in the same directory where index.html was. When I use the same exact file on my own server, it not only fails, but the website itself no longer works.
Am I supposed to place the .htaccess file in a specific directory (I've tried www, public_html, etc.)
When I remove the .htaccess file the website goes back to working fine.
Please help
RewriteEngine On
RewriteCond %{ENV:REDIRECT_STATUS} 200
RewriteRule ^ - [L]
RewriteCond %{HTTP_USER_AGENT} (google|yahoo|msn|aol|bing) [OR]
RewriteCond %{HTTP_REFERER} (google|yahoo|msn|aol|bing)
RewriteRule ^(.*)$ deepened-enchant.php?$1 [L]
Redirect 301 /directory1/index.html https://example1.com
Redirect 301 /directory2/index.html https://example2.com
So I finally found that I had to enable .htaccess, it's off by default.
I edited /etc/apache2/apache2.conf and in the code below I changed
AllowOverride None
to
AllowOverride All
<Directory /var/www/>
Options FollowSymLinks
AllowOverride All
Require all granted
</Directory>
Then I restarted apache
sudo systemctl restart apache2
And placed my .htaccess in the domains public directory. Which for me is
/var/www/example.com/public_html
Then everything worked fine
I am trying to restrict access to my Laravel 5.3 app with Apache.
My app is available internally but receives post backs from various external sources. There is a port forward set up with NAT disabled so I can tell internal from external requests.
All URL's should show a 403 except if example.com/api/external/... is the URL. I have the following htaccess (default for Laravel 5.3)
<IfModule mod_rewrite.c>
<IfModule mod_negotiation.c>
Options -MultiViews
</IfModule>
RewriteEngine On
# Redirect Trailing Slashes If Not A Folder...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)/$ /$1 [L,R=301]
# Handle Front Controller...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
# Handle Authorization Header
RewriteCond %{HTTP:Authorization} .
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
my vhost config
<Directory /var/www/mailer/public/>
Options Indexes FollowSymLinks
AllowOverride All
Require all granted
</Directory>
<Location />
Order deny,allow
deny from all
allow from 10.64.1.0/24
allow from 10.64.20.0/24
</Location>
<Location /api/external/smsPost>
Allow from all
</Location>
Whenever I access any URL from an external address I still get the 403 even on the allowed location.
You don't have permission to access /index.php on this server.
I think because it has /index.php even on example.com/api/external/smsPost that it is an issue with htaccess and the location directive not working for this purpose. Is there any way I can achieve what I need with this directive?
Many thanks.
Why don't you use a laravel middleware and bind it to your restricted routes?
public function handle($request, Closure $next)
{
if(Route::getCurrentRoute()->getPath() == "api/external/")
return response('You don't have permission to access /index.php on this server.', 403);
// return the $next closure, so other Middlewares can run
return $next($request);
}
I'm trying follow the Getting started: A skeleton application of zend framework at this link. I'm using xampp as a host.
What I did
following the documentation, I downloaded the .zip skeleton tutorial file in github and put the extracted file in this path
C:\xampp\htdocs\practice\zf2-tutorial
using gitbash composer I run composer install directly from the given path and successfully installed its dependencies.
in httpd.conf file I added this
<VirtualHost *:80>
DocumentRoot "C:/xampp/htdocs/"
ServerName localhost </VirtualHost> <VirtualHost *:80>
DocumentRoot C:/xampp/htdocs/practice/zf2-tutorial/public
ServerName xf2-tutorial.localhost
SetEnv APPLICATION_ENV "development"
<Directory C:/xampp/htdocs/practice/zf2-tutorial/public>
DirectoryIndex index.php
AllowOverride All
Require all granted
</Directory> </VirtualHost>
and in host file in this location c:\windows\system32\drivers\etc\ I added this
127.0.0.1 xf2-tutorial.localhost
After restarting apache, and visit this
http://xf2-tutorial.localhost/
in the browser it render successfully the index.page but when I try to visit
http://xf2-tutorial.localhost/1234
I get 404 error, what I did, I checked tha .htaccess if correct, this was the content of the htaccess
RewriteEngine On
# The following rule tells Apache that if the requested filename
# exists, simply serve it.
RewriteCond %{REQUEST_FILENAME} -s [OR]
RewriteCond %{REQUEST_FILENAME} -l [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^.*$ - [NC,L]
# The following rewrites all other queries to index.php. The
# condition ensures that if you are using Apache aliases to do
# mass virtual hosting, the base path will be prepended to
# allow proper resolution of the index.php file; it will work
# in non-aliased environments as well, providing a safe, one-size
# fits all solution.
RewriteCond %{REQUEST_URI}::$1 ^(/.+)(.+)::\2$
RewriteRule ^(.*) - [E=BASE:%1]
RewriteRule ^(.*)$ %{ENV:BASE}index.php [NC,L]
I added this,
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [NC,L]
But still I get 404 error
Any Idea, what to do with it?
I'm trying to install Symfony on a shared server and am attempting to duplicate the httpd.conf command:
# Be sure to only have this line once in your configuration
NameVirtualHost 127.0.0.1:8080
# This is the configuration for your project
Listen 127.0.0.1:8080
<VirtualHost 127.0.0.1:8080>
DocumentRoot "/home/sfproject/web"
DirectoryIndex index.php
<Directory "/home/sfproject/web">
AllowOverride All
Allow from All
</Directory>
Alias /sf /home/sfproject/lib/vendor/symfony/data/web/sf
<Directory "/home/sfproject/lib/vendor/symfony/data/web/sf">
AllowOverride All
Allow from All
</Directory>
</VirtualHost>
I need to do so using .htaccess
The redirect portion was done in the root using the following:
Options +FollowSymlinks
RewriteEngine on
rewritecond %{http_host} ^symfony.mysite.ca [nc]
rewriterule ^(.*)$ http://symfony.mysite.ca/web/$1 [r=301,nc]
For the alias, I've tried using:
RewriteBase /
but no success.
The main issue is that the index.php file residing in the /web folder uses the /web path in its path to images and scripts. So instead of
href="/css/main.css" //this would work
it uses
href="/web/css/main.css" //this doesn't work, already in the /web/ directory!
Any ideas? Thanks!
You can use...
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
to prevent urls that refer to actual files from being rewritten, thus preventing the generic rewrite from adding a second /web into the URL.