I have Apache 2.0.64 running in Windows 7. I visited lots of sites regarding installation and configuration of Apache. My config file is ok (I think). I can stop and restart the server without problems, but when try to access the page (localhost/market) then I get the 'Oops! Google Chrome could not connect to localhost' message.
I have written my RewriteRule within httpd.conf and I donot have .htaccess file in htdocs folder
Some values of my httpd.config may be helpful to you
ServerName localhost
Listen 80
DocumentRoot "C:/Apache/Apache2/htdocs"
<Directory "C:/Apache/Apache2/htdocs">
RewriteEngine On
RewriteRule ^(market|stock|mutual)$ stackoverflow/$1 [L]
Options Indexes FollowSymLinks
AllowOverride None
Order allow,deny
Allow from all
</Directory>
AccessFileName .htaccess
Please help me
I don't know what to do anymore...
If you are not able to access your page with localhost, try to access it with 127.0.0.1 IP address because this IP address points to localhost. Make the .htaccess file writable if it is not. Hope it helps.
Related
I have installed a nextcloud on my raspberrypi. I want to use it in my local network for file transfer and everywhere for contacts and the calendar.
My nextcloud is located at /var/www/html/nextcloud. I also created a file /etc/apache2/sites-available/nextcloud.conf to enable the virtual host. Basically:
<VirtualHost *:80>
DocumentRoot /var/www/html/nextcloud/
ServerName nextcloud.example.com
<Directory /var/www/html/nextcloud/>
Require all granted
AllowOverride All
Options FollowSymLinks MultiViews
<IfModule mod_dav.c>
Dav off
</IfModule>
</Directory>
SetEnv HOME /var/www/html/nextcloud
SetEnv HTTP_HOME /var/www/html/nextcloud
</VirtualHost>
The nextcloud is reachable for the following links:
192.168.2.100/nextcloud
nextcloud.example.com
example.com/nextcloud
My question: Is there a way to forbid the access via example.com/nextcloud?
I tried to add deny, allow entries into /var/www/html/nextcloud/.htaccess. But either I block too much, or it does not work. Help is appreciated.
The fact that example.com/nextcloud is accessible at all is because you're pointing the subdomain at a subdirectory off the main domain's document root (as defined in the main domain's VirtualHost). If the subdomain is an entirely separate entity then it would be preferable that it points to an area outside of the main domain's document root.
I tried to add deny, allow entries into /var/www/html/nextcloud/.htaccess
If you want to block this in .htaccess (as opposed to the main domain's vHost config) then you need to check the requested Host header. And in doing this I would have thought it would be preferable to block anything other than the canonical hostname, ie. anything other that nextcloud.example.com (so it also blocks requests via the IP address). Rather than checking for the hostnames you want to block. You can do this using mod_rewrite, for example:
# /var/www/html/nextcloud/.htaccess
RewriteEngine On
RewriteCond %{HTTP_HOST} !^nextcloud\.example\.com$
RewriteRule ^ - [F]
The above responds with a "403 Forbidden" for any request where the requested Host header is not (as denoted by the ! prefix) nextcloud.example.com.
You could also block this subdirectory in the main domain's vHost container (not the subdomain). So it only applies to requests to example.com. For example:
<Directory /var/www/html/nextcloud>
Require all denied
</Directory>
Note that Order, Allow and Deny are Apache 2.2 directives and formerly deprecated on Apache 2.4. You should be using Require (mod_authz_core) on Apache 2.4.
I have a strange problem in accessing to virtual host in WAMP.
I have defined my virtual host (it calls mvc.dev) by defining in server configuration page in wampserver. Steps are exact that I have explained in the following:
1- first, going to server configuration page and select Add a virtual host
2- As index.php in my project is in C:\wamp64\www\mvcdev\public path, so I fill out related fields for my virtual host and then start to creation of virtual host.
3- It is created correctly and wamp server wants to restart DNS manually. I restarted it from wamp server menu like this:
4- After restarting, I check localhost page. It shows that mvc.dev is created correctly without any problem
5- And the problem occurs here, when I click on mvc.dev or type it in address bar of browser to access my virtual host, it causes to download a file instead of loading index.php file. I'm so frustrated about this issue and I don't know how can I solve this. Why does it cause to download hex file instead of executing URL?
This file is a hex file and every time that I put mvc.dev in url, it will start to download this file
For your information, I have also tested it by defining virtual host manually. I put related codes in httpd-vhosts.conf and then define mvc.dev in host and then restart DNS, but the result is the same with thing that I have explained before and I can not access to my virtual host at all. You can see it in the following:
configuration in host file:
# localhost name resolution is handled within DNS itself.
# 127.0.0.1 localhost
# ::1 localhost
127.0.0.1 localhost
127.0.0.1 mvc.dev
::1 mvc.dev
configuration of httpd-vhosts.conf:
#
# Virtual Hosts
#
<VirtualHost *:80>
ServerName localhost
DocumentRoot c:/wamp64/www
<Directory "c:/wamp64/www/">
Options +Indexes +FollowSymLinks +MultiViews
AllowOverride All
Require all granted
</Directory>
</VirtualHost>
<VirtualHost *:80>
ServerName mvc.dev
DocumentRoot c:/wamp64/www/mvcdev/public
<Directory "c:/wamp64/www/mvcdev/public/">
Options Indexes FollowSymLinks MultiViews
AllowOverride All
Require local
</Directory>
</VirtualHost>
How can I solve this problem?
Note: I also checked this one by one but I couldn't solve my problem:
project-links-do-not-work-on-wamp-server
The .htaccess file is
# Remove the question mark from the request but maintain the query string
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?$1 [L,QSA]
The code in index.php is
echo 'Request URL is: '.$_SERVER['QUERY_STRING'];
//require '../core/Router.php';
require "../vendor/autoload.php";
$router = new Core\Router();
$router->add('/','HomeController#index');
I had the same issue and I found out that Chrome requires any *.dev to be access via HTTPS and any chromium base browser will negate localhost access to it. Check this link
Change the website extension to something else. That worked for me. For example instead of example.com use example.tst.
I am getting a weird issue i created a vhost in lamp stack. The problem is that when I open the vhost site www.domain.com the home page loads without any issue.
But when I use the nav bar to open another page I get a "404 NOT FOUND" i.e www.domain.com/about
But as soon as I put the extension of the file manually the page loads.
www.domain.com/about.php
How can I solve this issue. I am using .htaccess to hide the extension of the file.
Note:
1) All the other local file running properly i.e. I have a wordpress site that works fine (This means the mysql db is not causing the error)
2) The vhost is set properly bcus the terminal did not show any error when the vhost was enabled.
But the vhost in wamp does not give me any kind of issue in my windows 8.1 pro.
Edit :
Code in .htaccess to hide extension this works in my windows pc without any problem.
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.php -f
RewriteRule ^(.*)$ $1.php
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.html -f
RewriteRule ^(.*)$ $1.html
EDIT -2
<VirtualHost *:80>
<Directory /var/www/stab-website>
Options Indexes FollowSymLinks MultiViews
AllowOverride all
Order allow,deny
allow from all
</Directory>
DocumentRoot "/var/www/stab-website"
ServerName stab-site.com
ServerAlias www.stab-site.com
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
Still did not worked.
You need to enable the MultiViews options:
<VirtualHost *:80>
<Directory /var/www/htdocs>
Options Indexes FollowSymLinks MultiViews
</Directory>
ServerAdmin webmaster#dummy-host.example.com
DocumentRoot "/var/www/htdocs"
ServerName dummy-host.example.com
ServerAlias www.dummy-host.example.com
</VirtualHost>
This can either be done in your httpd.conf file, in the configuration file for your virtual host or in a .htaccess file.
You should also make sure so that the mod_negotiation module is enabled. This can be done by running:
sudo a2enmod negotiation
You also might need to verify that your virtual host configuration is fine, this can be done from the terminal using:
apache2ctl -t
After this you need to restart your server:
sudo service apache2 restart
From the documentation:
The effect of MultiViews is as follows: if the server receives a
request for /some/dir/foo, if /some/dir has MultiViews enabled, and
/some/dir/foo does not exist, then the server reads the directory
looking for files named foo.*, and effectively fakes up a type map
which names all those files, assigning them the same media types and
content-encodings it would have if the client had asked for one of
them by name. It then chooses the best match to the client's
requirements.
Thanks #Cyclone for your help
This post helped me to fix this issue
https://askubuntu.com/questions/233046/how-to-give-my-user-permission-to-add-edit-files-on-local-apache-server
The post above help to run Apache server as the logged in user.
To give rights to use .htaccess --
First, you should ensure that your username is included in www-data group. If not, you can add your username as www-data group
sudo adduser $USER www-data
After that, you should change the ownership of /var/www to your username
sudo chown $USER:www-data -R /var/wwws
And also don't forget to add this code in the apache2.conf
<Directory /var/www/ProjectRootDirectory>
AllowOverride All
</Directory>
I always have trouble when moving a site that I've developed in localhost into my hosting server with the .htaccess file. Specifically with relative paths to the files. It's not hard to fix, but it's quite bothering.
For example:
Whereas ErrorDocument 404 /foo/404.php works in the
hosting, for it to work in localhost I have to specify ErrorDocument
404 /projectroot/foo/404.php.
When using mod_rewrite, RewriteRule ^example/$ example.php [L,NC]
works in localhost, but for it to work in the hosting I must use
RewriteRule ^example/$ /example.php [L,NC] (note the slash before the file name).
It could be because I'm running localhost on Windows and my hosting is on Linux, but I don't think that's the problem.
So my question is, how can I ensure the paths to the files are correct when working locally or on the remote server? What is the "working directory" for the .htaccess file?
This may look slight more complicated then it seems, but I would work out your issue in the following way.
Create a dev domain on the C:\Windows\System32\drivers\etc\hosts file pointing to the IP 127.0.0.1 which is the localhost IP.
The domain name doesn't really matter just something easy for you to use for that given project for example test.dev so the hosts file would look like this:
# localhost name resolution is handled within DNS itself.
# 127.0.0.1 localhost
# ::1 localhost
127.0.0.1 localhost
127.0.0.1 test.dev
127.0.0.1 www.test.dev
Now define where the folder for that project will be, I will use c:\projects\test for this example.
Now create on your web server a new virtualhost for the domain you have just created, here is a sample of virtualhost that I use:
<VirtualHost *:80>
ServerAdmin root#localhost
DocumentRoot "C:/projects/test"
ServerName test.dev
ServerAlias www.test.dev
ErrorLog "C:/projects/logs/test.dev_error_log"
CustomLog "C:/projects/logs/test.dev_access_log" common
RewriteLog "C:/projects/logs/test.dev_rewrite_log"
RewriteLogLevel 9
ScriptAlias /cgi-bin/ "C:/projects/test/cgi-bin/"
<Directory "C:/projects/test">
Options -Indexes FollowSymLinks +ExecCGI
AllowOverride All
Order allow,deny
Allow from all
</Directory>
<Directory "C:/projects/test/cgi-bin">
AllowOverride None
Options None
Order allow,deny
Allow from all
</Directory>
</VirtualHost>
Restart your server to activate the changes, you do not need to restart the computer for the hosts file, it should work immediately once you save it.
Now you can use http://www.test.dev or http://test.dev and you can use the very same .htaccess on both, dev and live sites.
Some other tips:
Always use and define RewriteBase / as it can make a difference specially when you want to use rules without the / at the start, like you have mentioned for RewriteRule ^example/$ example.php [L,NC]
Depending on the rules you want to use, you may need to specify -MultiViews so I often just leave it on by default, like this:
Options +FollowSymLinks -MultiViews
As you can see on my virtualhost setup, I define the access, error and rewrite logs into the logs folder by default and with the domain name in question so when I need to see what is going on I have an easy access with the clear logs for that domain only and not my whole bunch of projects running on the same virualhost.
I guess that is about it, you don't really need that huge virtualhost that's just how I use it and its not like I need to copy and paste it all the time as I have my own simple script to create new domains and do all the work for me.
My web host points my "main" domain name to the root www folder. The web files for that site are located in the "www/app/webroot" folder. I currently have the site up and running using the following in the htaccess file:
RewriteBase /
RewriteEngine on
RewriteRule ^$ app/webroot/ [L]
RewriteRule (.*) app/webroot/$1 [L]
I'm trying to start a dev site for the same site. I made a folder named "dev" in the www folder. So, the web files for this folder are in: "www/dev/app/webroot" I have a sub-domain pointing to the dev folder. When I use the same htaccess as above in the dev folder, it doesn't work because (I believe) it is inheriting the settings from the root www folder. When the page loads, it just comes up blank. How do I set up my htaccess files to allow for both sites?
Thanks in advance for any help! I'm obviously a novice at this stuff.
So we'll try to clean the things :-)
Avoid using .htaccess. All the settings in a .htaccess in a directory /foo/bar can be set in apache configuration as a Directory setting (.haccess is usefull if you provide limited access on apache conf, if you own the server don't use it).
<Directory /foo/bar>(...)</Directory>
Then you can access your sites with named based virtualhosts. Verify you have this option:
NameVirtualHost *:80
When you have it nice things can start.
This will be your virtualhost for your 1st app:
<VirtualHost *:80>
ServerName app
ServerAlias www.app.somwhere.com
ServerAlias app.somwhere.com
DocumentRoot /www/app/webroot
<Directory />
Options FollowSymLinks
AllowOverride None
</Directory>
<Directory /www/app/webroot>
Options Indexes FollowSymLinks
# this prevent.htaccess reading, remove if you want .htaccess
AllowOverride None
# allow web access
Order allow,deny
allow from all
</Directory>
</VirtualHost>
Most apache settings can be define here. Only for your 1st app. Apache will serve this configuration for all requests done for the site name 'app', or 'www.app.somwhere.com', or 'app.somwhere.com'. You can define a lot of alias(ServerAlias)., and only one name (ServerName).
Then if you go in your browser and type http://app/ your browser won't find the server, so set it in your /etc/hosts. This is what every people wanting to access your app should have in the hosts file until you get a real DNS (assuming your 1st app is app.somwhere.com and the second foo.somwhere.com and 92.128.52.226is your external IP):
127.0.0.1 app.somwhere.com app foo foo.somewhere.com
92.128.52.226 app.somwhere.com app foo foo.somewhere.com
And now let's add another virtualhost for your second app:
<VirtualHost *:80>
ServerName foo
ServerAlias www.foo.somwhere.com
ServerAlias foo.somwhere.com
DocumentRoot /www/foo/webroot
<Directory />
Options FollowSymLinks
AllowOverride None
</Directory>
<Directory /www/foo/webroot>
Options Indexes FollowSymLinks
# this prevent.htaccess reading, remove if you want .htaccess
AllowOverride None
# allow web access
Order allow,deny
allow from all
</Directory>
</VirtualHost>
And etc.
Don't forget to restart your apache. No rewrite rule. nice virtualhosts is the 1st step of a nice configuration, you will be able to define rules, directory or location specific things per name used. Even php configuration can be set per virtualhost with php_value instead of a global shared one on php.ini.
type
apache2 -S
to get the list of your virtualhosts, you'll see that the first one is the 'default' one, if apache does'nt understand the name of the requested site it will serve this default one (so you could ad a specific virtualhost on top to handle theses cases).
Try adding dev/ to the paths in lines 3 and 4 to your dev .htaccess.
Maybe you should remove the "RewriteBase /" line in the .htaccess in your dev folder?