I'm using Wampserver on my windows computer, and my colleague is working on a mac with MAMP installed.
I changed my .htaccess file to get rid of the /public/ in the url, which worked fine, but this doesn't work on my buddy's computer with MAMP.
I have read you need to put all the files from the public folder in the root of the directory and change the paths.php and index.php. I've done this and it's not working because it is installed in a subfolder under the MAMP root, even tho I changed my .htaccess to adapt to this.
<IfModule mod_rewrite.c>
<IfModule mod_negotiation.c>
Options -MultiViews
</IfModule>
RewriteEngine On
RewriteBase /laravel/
# Redirect Trailing Slashes...
RewriteRule ^(.*)/$ /$1 [L,R=301]
# Handle Front Controller...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
</IfModule>
I've been looking at this all day and it's really annoying me that I can't find the solution.
So what is the best and secure way to do this? how do I need to do this to be able to let it work on MAMP and a shared hosting? (and if possible also wampserver, altho that's not a requirement)
I'm not a fan of virtual hosts on MAMP, if I need to buy MAMP PRO to avoid this then I will, that's not a problem :-). If this is only possible through virtual hosts, then I'll have to do it I guess.
Thanks for the help guys and gals!
Or you could both use the in-built php server that comes with artisan
$ php artisan serve
You don't need to manually edit any Apache files when doing this sort of thing in MAMP. Just select the directory you want to use for www using the option in the control panel:
You should setup up a vhost and add the domain to your hosts file. Don't do this through .htacces.
httpd-vhosts.conf
<VirtualHost *:80>
DocumentRoot /path/to/your/project/public
ServerName dev.yourproject.com
</VirtualHost>
Now edit your hosts file: http://helpdeskgeek.com/windows-7/windows-7-hosts-file/
Add this to your hosts file
127.0.0.1 yourproject.com
Now restart everything and your project should be available from http://dev.yourproject.com. Please don't use .htacces for this it is not necessary.
You can also try:
php -S localhost:7000 -t public/
This will fire up the PHP build in server on localhost:7000. Run the command from with the root of your project folder.
http://www.php.net/manual/en/features.commandline.webserver.php
Related
I have correctly setup my site locally and everything works. However, when I deployed that to a blank EC2 instance, I see that wp-json (Rest API) does not work. It works only when I put an index.php in between. In other words
This works locally:
http://localhost/wordpress/wp-json
But I need to have this on the EC2 server to make it work.
http://A.B.C.D/wordpress/index.php/wp-json
On the server, I have installed apache2 and I have not messed up with the configs yet. I am familiar with wordpress but I not so much familiar with config tweaks on apache. I have also gone thru thousands of previously posted questions, but none of them seem to answer my problem.
First, you need to have by a2enmod rewrite in your terminal.
Then in your Apache Configuration file, make sure you have the following:
<Directory #Wordpress directory here#>
Options Indexes FollowSymLinks
AllowOverride All #allows .htaccess directives in the next step
Require all granted
</Directory>
Then make sure you have the following content in your root .htaccess file:
RewriteEngine On
RewriteBase /wordpress/
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule (.+) index.php/$1 [L]
I'm trying to run a php project using apache configurations in LAMP but its not working*, whereas when I run it as php -S locahost:4000 its working really great.
Here is the link to the project if you need some info about the files or working of it Project
Here is my apache configuration -
<VirtualHost localhost:4000>
ServerAdmin root#localhost
ServerName localhost
ServerAlias localhost
DocumentRoot /var/www/html/dir
<Directory "/var/www/html/dir">
AllowOverride None
Options None
Require all granted
</Directory>
*not working means - when running it through apache i can only access the index page and when going to some other page of the project like localhost:4000/about It shows The requested URL /department was not found on this server. ie. Error 404.
I think that you expect "index.php" to receive all requests.
Now, Apache is trying to find "about" directory and "department" directory.
In order for Apache to run index.php on any URL, we need to use the Rewrite rule.
Although I have not verified it in detail, I guess it will work with the following rules.
RewriteEngine on
RewriteRule ^/(.*)$ /index.php
It now working after enabling a2enmod rewrite from apache and updating the contents of .htaccess file as follows
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /index.php?path=$1 [NC,L,QSA]
I have a simple problem here. I'm a beginner in using php and apache. Actually I want to modify some config in my .htaccess but i cant find in. Can anyone tell me where is it located. TIA.
.htaccess sets directory specific settings and it can go in each web directory as needed to change settings.
Some server packages will include a blank/basic one in the root www dir.
If XAMPP doesn't include one, just create a text file and name it .htaccess and edit it however you need.
.htaccess includes in your project like if you're working on wordpress and whatever you named the folder, just enter that folder and search it you may find it.
here you may see
see .htaccess file is usually present in your C:/xampp/htdocs/wordpress if you are in windows or /opt/lampp/htdocs/wordpress if you are on linux or mac if you can't find it simply...
( for Windows )
enable show hidden files in file manager...
(for linux)
open terminal and type...
cd /opt/lampp/htdocs/wordpress
sudo ls -a
here it will show if it is present and if not simply make a direcroy...
sudo touch .htaccess
and paste the .htaccess you will see at wordpress by typing...
sudo gedit .htaccess
and here paste the following...
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
RewriteBase /wordpress/
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /wordpress/index.php [L]
</IfModule>
and you're ready to go...
Hope your issue is resolved...
Thank You have a nice day... :)
You can create one .htaccess file in the XAMPP's htdocs folder which you can customize or use as you want.
sorry if this is a duplicate but pretty confusing reading all others post..
This is for laravel4 framework
I know that when offline we can use mod rewrite with virtual host to make directory such as
c:/laravel4/public and c:/laravel4/public/posts
into
www.l4.com and www.l4.com/posts which runs on browsers
but when I'm hosting it upon real domain how can I change something like
sample.com/laravel4/public/posts
into
sample.com/posts
Thanks in advance for any help~!
Edit:
Sorry I didn't mention my OS it's windows in my local computer but in my domain account it says OS is Linux with php5.3
My original .htaccess which is under the public folder has such code in it
<IfModule mod_rewrite.c>
Options -MultiViews
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
</IfModule>
how can I change something like sample.com/laravel4/public/posts into sample.com/posts
Place this code in your DOCUMENT_ROOT/.htaccess file:
RewriteEngine On
RewriteRule !^laravel4/public/ /laravel4/public%{REQUEST_URI} [L,NC]
If you want URL as: www.mydomain.com/laravel4/posts then place this code in your DOCUMENT_ROOT/.htaccess file:
RewriteEngine On
RewriteRule ^laravel4/((?!public/).*)$ /laravel4/$1 [L,NC]
When using Laravel, you should point Apache to your public folder as the location from where it serves the site, not the root of Laravel.
You need to enable mod rewrite as the previous fellow said and I am going to assume you are using linux (ubuntu) since you didn't specify your OS. You can enable mod_rewrite by typing this in the terminal.
sudo a2enmod rewrite
then restart apache
sudo service apache2 restart
Once that is done go to
/etc/apache2/sites-available
assuming you are using apache and a linux (ubuntu) server. The look for your domains site, or in case you are using the default host, open it up with your favourite text editor and change this line to point to your public directory
DocumentRoot /path-to-your-folder/public
eg DocumentRoot /var/www/domain/public
Save the file and restart apache with the command;
sudo service apache2 restart
You should be good to go without typing public in your url.
Thus www.l4.com/public/posts will now become www.l4.com/posts
I am using Zend Framework on Ubuntu 11.10 (my local dev machine). When I navigate to my application with this URL, the front page/index controller works fine:
http://localhost/myapp/public
So I know that for the most part everything is working. The problem comes when I try to access another controller with something like:
http://localhost/myapp/public/faq
This returns the 404 error "The requested URL /myapp/public/faq was not found on this server."
I used the Zend_Tool to create the controller like "zf create controller faq" which gave me FaqController.php with a default indexAction(). It also created the faq.phtml view. This all works just fine on my laptop (Windows XP) so I know it has to be something with configuration.
Here is my .htaccess (it's the default one):
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} -s [OR]
RewriteCond %{REQUEST_FILENAME} -l [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^.*$ - [NC,L]
RewriteRule ^.*$ index.php [NC,L]
In an attempt to get it to work, I added this into my httpd.conf file and restarted apache:
<Directory />
Options FollowSymLinks
AllowOverride All
Order allow,deny
Allow from all
</Directory>
When that didn't work I tried putting that directly into my .htaccess file, but that was a no-go as well. What am I missing? What is stopping Zend from being able to rewrite and route requests?
[SOLVED]
Thanks for viewing, I ended up finding the solution. With Ubuntu, in the /etc/apache2/sites-enabled/ directory is a file called 000-default which contains configuration options.
I was unaware it was there, it had all the AllowOverride options set to None so I changed them to All, restarted Apache, and voila!
To ensure anybody who finds this question via search has full help, I'd like to pass on to make sure mod_rewrite is enabled (mine was) by opening a terminal and running:
sudo a2enmod rewrite
That is how you enable an Apache mod in Ubuntu.