I placed my rewrite rules inside directory tag.
Before I asked the question I've read Apache documentation where is written:
A web-path to a resource
RewriteRule ^/foo$ /bar
If DocumentRoot is set to /usr/local/apache2/htdocs, then this directive would map requests for http://example.com/foo to the path /usr/local/apache2/htdocs/bar.
So I did as written.
In example below I want: /aaaaa to redirect to /index.php?action=aaaaa
<VirtualHost *:80>
ServerAdmin webmaster#localhost
ServerName test.com
DocumentRoot /var/www/project/released/test
<Directory /var/www/project/released/test>
AllowOverride none
Options Indexes FollowSymLinks MultiViews
Order allow,deny
allow from all
RewriteEngine on
RewriteRule ^/([a-z0-9-_]+)$ /index.php?action=$1 [NC,L]
</Directory>
</VirtualHost>
In apache log is written:
[Mon May 27 23:14:11 2013] [error] File does not exist: /var/www/project/released/test/aaaaa
Could you please help and advice why this may not work and why the log shows totally different behavior (obviously this path does not exist but it never should, according to the doc!)? I have mod_rewrite installed and enabled.
Related
My application is in Laravel + Vue I'v hosted on Hostinger VPS ubuntu 20.
when I type my site in Google like exptradies.com google showing all the directories as bellow image.
This is my site config
<VirtualHost *:80>
ServerName exptradies.com
ServerAlias www.exptradies.com
ServerAdmin admin#exptradies.com
DocumentRoot /var/www/html/exptradies/public
<Directory /var/www/html/exptradies>
AllowOverride All
Options +FollowSymlinks
Require all granted
ReWriteEngine On
</Directory>
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
RewriteEngine on
RewriteCond %{SERVER_NAME} =www.exptradies.com [OR]
RewriteCond %{SERVER_NAME} =exptradies.com
RewriteRule ^ https://%{SERVER_NAME}%{REQUEST_URI} [END,NE,R=permanent]
</VirtualHost>
Does anyone know What I'm missing in the configuration.
for the ssl I use Letsencypt cerbot.
Your web server is configured to show directory indexes. That shows a web page with a list of files for directory requests when the directory does not contain an index document. You can disable this by using
Options -Indexes
That can either go beneath AllowOverride All or in your .htaccess file.
After making the configuration change you will have to wait a couple weeks for Googlebot to recrawl those pages and stop indexing them.
Add public to your path in Directory and this probably will solve your problem
<Directory /var/www/html/exptradies/public>
AllowOverride All
Options +FollowSymlinks
Require all granted
ReWriteEngine On
</Directory>
Don't forget to restart apache service
I'm running Ubuntu 20.04 lts with Apache 2. I enabled mod_rewrite, but when my rules are enabled it results in a 404 error.
This is my current (stripped down) .htaccess file and I still get a 404:
RewriteEngine On
RewriteRule ^([a-zA-Z0-9_-]+)(|/)$ index.php?page=$1
I've configured my virtualhost like so:
<VirtualHost *:80>
ServerName website
ServerAlias www.website
ServerAdmin webmaster#localhost
DocumentRoot /var/www/website
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
<Directory /var/www/website/>
Options Indexes FollowSymLinks MultiViews
AllowOverride All
Require all granted
</Directory>
</VirtualHost>
What have I done wrong? It works on IIS.
Nvm already solved it, somehow the MultiViews option was causing trouble or I made a type error.
replaced
Options Indexes FollowSymLinks MultiViews
with this
Options Indexes FollowSymLinks
And it works now
it's my first time to use laravel and config apache and I've a problem with apache document root, it doesn't change.
It always show apache homepage
I'm using a vm with virtualbox, and my conf.d file finish with this lines:
DocumentRoot "/var/www/laravel/public"
<VirtualHost *:80>
ServerAdmin webmaster#localhost
ServerName 192.168.56.3
#ServiceAlias www.test.laravel.com
DocumentRoot /var/www/laravel/public
</VirtualHost>
<Directory "/var/www/laravel/public">
Options FollowSymLinks
ReWriteEngine On
Options Indexes FollowSymLinks Includes ExecCGI
AllowOverride All
Require all granted
RewriteEngine On
RewriteRule ^(.*)$ public/$1 [L]
</Directory>
Do you know what is wrong?
Thank you
I have a problem, let me explain.
Rewrite_module is enabled on WAMP
My host is mapped:
127.0.0.1 localhost
127.0.0.1 mydomain.com
My vhost declared on WAMP:
<VirtualHost *: 80>
ServerAdmin contact#mydomain.com
DocumentRoot "E:/wamp/www/subfolder/"
ServerName mydomain.com
ErrorLog "logs/mydomain.com.log"
CustomLog "logs/mydomain.com.log" common
<Directory "E:/wamp/www/subfolder /">
Options Indexes FollowSymLinks MultiViews
AllowOverride All
Order allow, deny
Allow from all
</ Directory>
</ VirtualHost>
For now, no problem, mydomain.com arrives on E:/wamp/www/subfolder/
My projects are in sub folders such as E:/wamp/www/subfolder/my-project/
I have a htaccess with:
<Mod_rewrite.c IfModule>
RewriteEngine On
RewriteBase /my-project/
RewriteRule ^index\php$ - [L]
RewriteRule ^assets/css/(.*) /my-project/content/themes/assets/css/ $ 1 [QSA, L] [QSA, L]
RewriteCond% {REQUEST_FILENAME}! F
RewriteCond% {REQUEST_FILENAME}! -d
RewriteRule. /my-project/index.php [L]
</ IfModule>
My problem comes here. If I go on mydomain.com/my-project/ it comes to the site with no problem, but the css (for example) are not loaded, because the link is:
mydomain.com/content/themes/assets/css/
It should have:
mydomain.com/my-project/content/themes/assets/css/
I think the RewriteBase not working and I do not know why.
Thank you very much and sorry for my english.
I think you misunderstood the point of a Virtual Host.
You should create a Virtual Host for EACH of your projects so something like this
<VirtualHost *: 80>
ServerAdmin contact#mydomain.com
DocumentRoot "E:/wamp/www/subfolder/project1"
ServerName mydomain1.com
ErrorLog "logs/mydomain.com.log"
CustomLog "logs/mydomain.com.log" common
<Directory "E:/wamp/www/subfolder/project1">
Options Indexes FollowSymLinks MultiViews
AllowOverride All
Order allow, deny
Allow from all
</Directory>
</VirtualHost>
<VirtualHost *: 80>
ServerAdmin contact#mydomain.com
DocumentRoot "E:/wamp/www/subfolder/project2"
ServerName mydomain2.com
ErrorLog "logs/mydomain.com.log"
CustomLog "logs/mydomain.com.log" common
<Directory "E:/wamp/www/subfolder/project2">
Options Indexes FollowSymLinks MultiViews
AllowOverride All
Order allow, deny
Allow from all
</Directory>
</VirtualHost>
This makes each project look and react like it was a single website on its own unique Apache instance and makes moving your projects to live servers more reliable.
You also do not need a .htaccess now unless this one project actually requires it.
localhost/mysite/public - working
localhost/mysite/public/index.php/tasks - working
localhost/mysite/public/tasks - NOT WORKING ERROR 404
I tried almost everything and still have problem.
I have got mod rewrite on - i used : sudo a2enmod vhost_alias rewrite
and restarted the server
my .htaccess file:
<IfModule mod_rewrite.c>
Options +FollowSymLinks
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]
</IfModule>
my etc/apache2/sites-avaliable/default its like:
<VirtualHost *:80>
ServerAdmin webmaster#localhost
DocumentRoot /var/www/
<Directory />
Options FollowSymLinks
AllowOverride None
</Directory>
<Directory /var/www/>
Options Indexes FollowSymLinks MultiViews
AllowOverride None
Order allow,deny
allow from all
</Directory>
ScriptAlias /cgi-bin/ /usr/lib/cgi-bin/
<Directory "/usr/lib/cgi-bin">
AllowOverride None
Options +ExecCGI -MultiViews +SymLinksIfOwnerMatch
Order allow,deny
Allow from all
</Directory>
ErrorLog ${APACHE_LOG_DIR}/error.log
# Possible values include: debug, info, notice, warn, error, crit,
# alert, emerg.
LogLevel warn
CustomLog ${APACHE_LOG_DIR}/access.log combined
Alias /doc/ "/usr/share/doc/"
<Directory "/usr/share/doc/">
Options Indexes MultiViews FollowSymLinks
AllowOverride None
Order deny,allow
Deny from all
Allow from 127.0.0.0/255.0.0.0 ::1/128
</Directory>
</VirtualHost>
when I change AllowOverride to All - only "localhost/" is working but i cant run any sites like "localhost/mysite" .
I have tried to add to default file a next virtual host like:
<VirtualHost *:80>
DocumentRoot /var/www/mysite/public/
<Directory /var/www/mysite/public/>
AllowOverride All
</Directory>
</VirtualHost>
but it is not working at all.
First, if you are using Laravel 3 make sure that you have updated /application/config/application.php and made the "application index" var to a null value, like "". https://github.com/laravel/laravel/blob/master/application/config/application.php#L42
If you've already done that, try setting up a vhost. It sounds like you are using Apache 2.
First create an additional vhosts file, for example /etc/apache2/sites-available/laravel
<VirtualHost *:80>
ServerAdmin webmaster#localhost
ServerName laravel.dev
ServerAlias *.laravel.dev
DocumentRoot /home/kriss/projects/laravel/public
</VirtualHost>
Then update your /etc/hosts file and add
127.0.0.1 laravel.dev
Then (and this may be the step you missed before)
sudo a2ensite laravel
This will make a sim link in /etc/apache2/sites-enabled to your vhost config file.
Finally restart your server:
sudo service apache2 restart
You should be able to connect with the url http://laravel.dev, and your rewrites should be working.
Run the following command in Terminal to enable mod_rewrite.
sudo a2enmod rewrite
Now restart Apache.
sudo service apache2 restart