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
Related
We have two hosting packages at godaddy. Our live website is working fine using following .htaccess file. Website is accessible without using index.php in url.
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?/$1 [L]
We used same htaccess file and same code on other hosting that is also by godaddy. We just wanted to make production and development instances seperate. But on other hosting with same code and htaccess file, website shows 404 page not found error but website works fine with index.php in url.
We have same php version on both server. Just wants to know what could be the issue?
I also faced the similar problem when I move my 100% working code to dedicated Debian server. After 3 hours of research, i found out why htaccess file is not working.You need to allow overriding of htaccess in Apache Configuration.
Here are the steps.
Step 1:
Add this in htaccess file
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L,QSA]
</IfModule>
Step 2:
Remove index.php in codeigniter config
$config['index_page'] = '';
Step 3:
Allow overriding htaccess in Apache Configuration (Command)
sudo nano /etc/apache2/apache2.conf
and edit the file & change to
AllowOverride All
for www folder
Step 4:
Restart Apache (Command)
sudo /etc/init.d/apache2 restart
Before you make any changes in apache2.conf file make sure to make a backup copy of that file. If you are using Debian server you can avoid sudo command. I believe you know how to connect to your server using ssh client software like putty. Comment below if this method does not work for you.
Follow this
Create a new .htaccess file in your public_html/Project root
Paste the following code
RewriteEngine on
RewriteBase /
RewriteCond $1 !^(index\.php|resources|robots\.txt|static) [NC]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/?$1 [L,QSA]
Optional
If you can ssh into the server using command ssh username#ip_address on a command line either Linux terminal or Putty
The username is the one given to you by GoDaddy or you can use root
The ip_address would be the Public IP to your host you can find it in your hosting panel
Run the command sudo a2dissite 000-default
The command disables the default apache config that handles request
Goodluck!
You can use this. This works for me in godaddy hosting.
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*) index.php?/$1
try this one.. it's works for me..
DirectoryIndex index.php
RewriteEngine on
RewriteCond $1 !^(index\.php|images|css|js|robots\.txt|favicon\.ico)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ ./index.php?/$1 [L,QSA]
I have faced the similar problem when I move on godaddy server.And It's work for me.
Add this code into your .htaccess file.
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
# Rewrite all other URLs to index.php/URL
RewriteRule ^(.*)$ index.php?url=$1 [PT,L]
</IfModule>
<IfModule !mod_rewrite.c>
ErrorDocument 404 index.php
</IfModule>
In config file:
$config['base_url'] = 'domain.com';
$config['index.php'] = '';
And Set AllowOverride to All in your httpd.conf
set the correct permission on the /cache folder, rather than just making the folder writable you need to make it reclusively writable.
I hope it will work for you.
Try to lowercase all your controllers. This fix the problem for me.
in index.php you echo "test" and run .then you can check whether it is called or not.
in config file enable error log .
Make your /application/logs folder writable.
In /application/config/config.php set. $config['log_threshold'] = 4;
check the log /application/logs folder
I have limited knowledge in server networking but this should give you a few ideas.
First ,you must know what is .htacess file is. you can check it here link
.htaccess is a configuration file for use on web servers running the
Apache Web Server software. When a .htaccess file is placed in a
directory which is in turn 'loaded via the Apache Web Server', then
the .htaccess file is detected and executed by the Apache Web Server
software. These .htaccess files can be used to alter the configuration
of the Apache Web Server software to enable/disable additional
functionality and features that the Apache Web Server software has to
offer. These facilities include basic redirect functionality, for
instance if a 404 file not found error occurs, or for more advanced
functions such as content password protection or image hot link
prevention.
Basically .htaccess is giving you permission to edit the configuration of Apache Web Server. You will gain permission using .htacess if mod_rewrite is enabled in Apache. I will not write what that 4 basic line in .htaccess can do in codeigniter because you can find it in google. this link can give you some nice basic info.
Now the main issue is .htaccess is not working in your other hosting. This is possible because a few reason :
For some reason, mod_rewrite is disabled in your Apache Web Server. If your hosting is VPS or DS it's possible you are didn't configuring it yet. Someone already ask how to enable mod_rewrite, you can go to this link. If you are using Shared Hosting, ask your hosting to enable mod.rewrite in your host. You can check if mod.rewrite enabled or not in your hosting following this link. Or you can simply check with <?php phpinfo(); ?> and check in "Loaded Modules" for mod_rewrite exist or not. Example in this image.
You are not using Apache as Web Server. There are others Web Server as NGINX and lighttpd. You should ask your server administrator what Web Server are you use currently. I dont have any experience using NGINX and lighttpd so i cannot give you any help in that. But as far as i know .htaccess code is different in APACHE, NGINX, and lighttpd. You can try to convert .htaccess apache code to nginx code in here or here. For converting .htaccess to lighttpd unfortunately, i cannot find any online converter but there are official guide here and here
Well for the complete tips sake i will write this. It's possible you are not configuring codeigniter to not use index.php. In config file, empty configuration for index_page. and give Base_url your domain name. $config['base_url'] = "yourdomainname.com"; $config['index_page'] = '';
I hope this clear your confussion why your .htaccess didnt work.
As you mentioned here, on localhost your code is working fine but when you moved it over live server it causes 404 error. There might be few cases you need to check:
Step 1: Check mod_rewrite is enabled or not in your Apache configuration
Step 2: Remove index.php in codeigniter config as #geordy suggested
You can check it by
<?php
echo 'Test'; die;
?>
in your root index.php. It ensures your all requests should go through this files else Codeigniter framework would not work properly.
I have written URL rewrite like this
Options +FollowSymlinks
RewriteEngine on
RewriteRule ^home index.php
RewriteRule ^process login_do.php
RewriteRule ^logout logout.php
RewriteRule ^request event-request.php
RewriteRule ^gallery event-gallery.php
RewriteRule ^press-releases/([0-9]+)$ press_releases.php?y=$1
RewriteRule ^single_pr/([0-9]+)$ single_pr.php?id=$1
and it is working perfectly on IIS server after converting this into webconfig
but when I deployed my application on XAMPP Linux it is not working and showing,
REDIRECT loop on browser.
Can anyone guide me how to add port number and folder name in the URL rewrite, because I think IIS is considering localhost/myapplicaiton as localhost/index.php so that is why it is working in IIS.
Guide me for Linux and Windows.
I have found the solution, issue was related to mod_rewrite function was disabled in apache in linux operating system.
To find out mod_rewrite is enabled or disabled.
just run php_info() and search for mod_rewrite. this is an easy technique, there are multiple ways to find out mod_rewrite.
To enable mod_rewrite, go to your linux terminal and type this command a2enmod rewrite and restart apache php_info().
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
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.
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.