I know this question have more answer on this page. But It is not work fine for me. I don't know why. I followed step by step as instruction. Could you please help me check.
Thanks for your support
The URL looks liks is : examplemysite.com
The link work well if I add index.php for it.
Change config.php -> $config['index_page'] = '';
$config['uri_protocol'] = 'REQUEST_URI';
htaccess is located same level with index.phpenter image description here
The content of htaccess
RewriteEngine on
RewriteCond $1 !^(index\.php|resources|robots\.txt)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L,QSA]
In to enable mod_rewrite for Windows and Linux, do the following:
Windows:
Find and open the file .http.conf. This will be located in your Apache install folder.
Make a backup of http.conf which you can restore from, if anything were to go wrong
Find the line #LoadModule rewrite_module modules/mod_rewrite.so and remove the hash ‘#’enable-mod-rewrite-1
Locate the block within the directory tags as indicated below and change to:
Options All
AllowOverride All
Finally, restart apache server and your browser. The .htaccess rewriting should now be working.
Linux (Ubuntu as an example):
Activate the mod_rewrite module with
sudo a2enmod rewrite
and restart the apache
sudo service apache2 restart
To use mod_rewrite from within .htaccess files edit the virtualhost
sudo nano /etc/apache2/sites-available/000-default.conf
Below “DocumentRoot /var/www/html” add the following lines:
<Directory “/var/www/html”>
AllowOverride All
</Directory>
Restart the server again:
sudo service apache2 restart
Related
The last one I follow is here How to remove index.php from codeigniter in UBUNTU [duplicate]
I have one controller that look like this:
<?php
defined('BASEPATH') OR exit('No direct script access allowed');
class Login extends CI_Controller {
public function index()
{
$this->load->view('login.html');
}
}
When I access it by this URL: http://localhost/homerent/Login, I got 404 not found.
I follow from answer above in referent link by
$config['index_page'] = '';
restart apache2 service: sudo /etc/init.d/apache2 reload
Add below code to /var/www/html/my_ci_site/.htaccess
RewriteEngine on
RewriteBase /
RewriteCond $1 !^(index\.php|static|robots\.txt|favicon\.ico|uploads|googlexxxxxxxx\.html|mobile.html)
RewriteRule ^(.*)$ index.php/$1 [L]
Replace every instance of AllowOverride None to AllowOverride All in /etc/apache2/apache2.conf
Enable rewrite mode: sudo a2enmod rewrite
Finally restart apache2 service again.
After all, I access my url again http://localhost/homerent/Login I still get 404 not found.
I have no clue what is wrong with that.
In Ubuntu You have to do virtual host to working.
For this first in /etc/apache2/sites-available create yourproject.conf file(may be you may need root permissions use sudo command)
For this in terminal
cd /etc/apache2/sites-available
Then
sudo nano yourproject.conf
Copy below content and paste into it
<VirtualHost *:3434>
ServerName localhost
DirectoryIndex index.php
DocumentRoot /var/www/html/yourprojectfolder
<Directory "/var/www/html/yourprojectfolder">
Options All
AllowOverride All
Allow from all
</Directory>
</VirtualHost>
Note:You can use different ports here
Then run
sudo nano /etc/apache2/ports.conf
In this file add line (Do not edit existing ports )
Listen 3434
Then run
sudo a2ensite yourproject.conf
sudo a2enmod rewrite
in config.php
$config['base_url'] = 'http://localhost:3434';
$config['uri_protocol'] = 'REQUEST_URI';
$config['index_page'] = '';
Create .htaccess inside yourproject folder with below content
RewriteEngine on
RewriteCond $1 !^(index\.php|images|robots\.txt)
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ index.php/$1 [L]
Then restart apache to take effect the changes
Now you can access your site through the url http://localhost:3434(This will load the defaulf controller) and no need to add the project folder in the url
for example http://localhost/homerent/Login is the url using now and
After setting up virtual host
You can use http://localhost:3434/Login
I have my files in ubuntu server. I have a .htaccess file in my project. And i am not able to access that file in the server. I want to enable .htaccess files in my server. How to do?
This is my code in my /var/www/html/.htaccess
RewriteEngine on
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteCond %{REQUEST_URI} !/$
RewriteRule ^(.*)$ $1\.php
Please help.
To enable .htaccess (mod_rewrite)
Login to SSH and do follwing,
john#doe:~$ sudo a2enmod rewrite
john#doe:~$ sudo service apache2 reload
Usually this is how the rewrite module is enabled in Ubuntu.
To view and edit hidden files via terminal.
john#doe:~$ cd /var/www/html/your_website_root/
john#doe:~$ ls -la # this command will display all files including hidden files.
john#doe:~$ vi .htaccess # to edit the htaccess file
You can use vi, vim and nano etc.. for editing files via terminal.
If still the htaccess not working, do following change in the virtual host entry.
Change
Options Indexes FollowSymLinks MultiViews
To
Options Indexes FollowSymLinks
I hope this helps.
I need some help with laravel 4 application i need to remove Index.php from url i have tried the solution that has been mentioned in laravel documentation
Pretty URLs
Apache
The framework ships with a public/.htaccess file that is used to allow URLs without index.php. If you use Apache to serve your Laravel application, be sure to enable the mod_rewrite module.
If the .htaccess file that ships with Laravel does not work with your Apache installation, try this one:
Options +FollowSymLinks
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
any Suggestions :) ?
FOR LAMP SERVER
Try the following steps,
Activate the mod_rewrite module with,
sudo a2enmod rewrite
and restart the apache
sudo service apache2 restart
To use mod_rewrite from within .htaccess files (which is a very common use case), edit the default VirtualHost with
sudo nano /etc/apache2/sites-available/000-default.conf
Search for “DocumentRoot /var/www/html” and add the following lines directly below:
<Directory "/var/www/html">`
AllowOverride All
</Directory>
Save and exit the nano editor via CTRL-X, “y” and ENTER.
Restart the server again:
sudo service apache2 restart
this worked for me
<Directory "/var/www/html">`
AllowOverride All
</Directory>
uncomment 'LoadModule rewrite_module modules/mod_rewrite.so' in apache httpd.conf
in 'public' folder check .htaccess file (created by default)
<IfModule mod_rewrite.c>
<IfModule mod_negotiation.c>
Options -MultiViews
</IfModule>
RewriteEngine On
# 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 have read long posts and threads but nothing works then i found this and it works for me.
The easiest way to do this (and the way I always use) is to open up your Command prompt or Terminal and cd into the main directory of your project then run "php artisan serve". That's it. You're done. Don't believe me? Check out http://localhost:8000 and admire your Laravel work.
http://michaelbrooks.co.uk/post/laravel-localhost-removing-public-index-php
just go to your apache settings folder, i use wamp so myne is
C:/wamp/bin/apache/apache2.4.9/conf/httpd.conf - file
// located on line 154 precisely...
#LoadModule rewrite_module modules/mod_rewrite.so
// to
LoadModule rewrite_module modules/mod_rewrite.so
restart WAMP and BOOM!.. it works.
mod_rewrite apache module may not be enabled by default. enable it and retry.
Try this:
a2enmod rewrite
And it will works
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 currently trying to learn about clean urls. i was using windows once.
i switched to ubuntu when suddenly my .htaccess seems to be not working
here is my htaccess
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?/$1 [L]
</IfModule>
so i have this url
http://localhost/index.php/my_name/
i was expecting it to say the 'my_name' string in the browser
hello my_name
but it would only work whenever i add a '?' in the uri
http://localhost/index.php?/my_name/
i am pretty sure mod_rewrite is enabled. i even checked my phpinfo()
It sounds like the rewrite module is disabled. Edit your apache configuration and load the dynamic module for mod_rewrite if available. It would look like this:
LoadModule rewrite_module modules/mod_rewrite.so
If you're using Ubuntu, run sudo a2enmod rewrite to enable the module following by restarting the Apache server:
sudo /etc/init.d/apache2 restart
Found a solution. dumped the $_SERVER variable and used the REQUEST_URI index since QUERY_STRING does not display anything. will +1 Lekensteyn's answer since it led me to the right path