Pages

Showing posts with label mod_rewrite. Show all posts
Showing posts with label mod_rewrite. Show all posts

Sunday, September 29, 2013

CodeIgniter-Seo Urls

1. I am using ubuntu 13.04. To setup mod_rewrite on debian based machines ubuntu is in concern here go through my this post

http://itfeast.blogspot.in/2013/09/cakephpubuntu-setting-up-cakephp-on.html

If you are assured that mod_rewrite is working perfectly on your Apache Server Proceed Further.

Now We will proceed with configuring CodeIgniter for seo urls

2. Remove Index.php

Your root .htaccess should look like this

 <IfModule mod_rewrite.c>  
 # Turn on URL rewriting  
 RewriteEngine On  
 # If your website begins from a folder e.g localhost/my_project then   
 # you have to change it to: RewriteBase /my_project/  
 # If your site begins from the root e.g. example.local/ then  
 # let it as it is  
 RewriteBase /ci/  
 # Protect application and system files from being viewed when the index.php is missing  
 RewriteCond $1 ^(application|system|private|logs)  
 # Rewrite to index.php/access_denied/URL  
 RewriteRule ^(.*)$ index.php/access_denied/$1 [PT,L]  
 # Allow these directories and files to be displayed directly:  
 RewriteCond $1 ^(index\.php|robots\.txt|favicon\.ico|public|assets|css|js|images)  
 # No rewriting  
 RewriteRule ^(.*)$ - [PT,L]  
 # Rewrite to index.php/URL  
 RewriteRule ^(.*)$ index.php/$1 [PT,L]  
 </IfModule>  

3. Now in application/config/config.php

change
$config['index_page'] = 'index.php';
to
$config['index_page'] = '';

In some cases you may also need to configure

$config['uri_protocol'] = 'AUTO';

To

$config['uri_protocol'] = 'PATH_INFO';

Or To

$config['uri_protocol'] = 'REQUEST_URI';

4. Now your folder structure should look like this

website_folder/ 
–––– application/ 
–––– system/ 
–––– user_guide/ 
====>.htaccess
–––– index.php 
–––– license.txt
 
You might also go for custom routing further as
 
$route['default_controller'] = 'webpages'; //Our default Controller

//Get rid of the first segment (in our case we get rid of webpages)
$route["about"] = 'webpages/about'; 
$route["blog/(.*)"] = 'webpages/blog/$1';
$route["view/(.*)"] = 'webpages/view/$1';
 
Source: http://www.web-and-development.com/codeigniter-remove-index-php-minimize-url/ 

Sunday, September 15, 2013

Cakephp,Ubuntu-Setting Up Cakephp on Ubuntu Server/Enabling Mode_Rewrite

Recently while installing Cakephp on Ubuntu Server I face some initial setup errors.

1. Firstly rewrite_module was not enabled I enabled it using the following commands

sudo a2enmod rewrite

2.  Needed to Enable AllowOverride All For this I modified following file

/etc/apache2/sites-available/default



 <VirtualHost *:80>  
      ServerAdmin webmaster@localhost  
      DocumentRoot /var/www  
      <Directory />  
           Options FollowSymLinks  
           AllowOverride All  
      </Directory>  
      <Directory /var/www/>  
           Options Indexes FollowSymLinks MultiViews  
           AllowOverride All  
           Order allow,deny  
           allow from all  
      </Directory>  
      ScriptAlias /cgi-bin/ /usr/lib/cgi-bin/  
      <Directory "/usr/lib/cgi-bin">  
           AllowOverride All  
           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 All  
     Order deny,allow  
     Deny from all  
     Allow from 127.0.0.0/255.0.0.0 ::1/128  
   </Directory>  
 </VirtualHost>  


3. Finally restart Apache

 sudo /etc/init.d/apache2 restart

Sunday, July 8, 2012

Check the status of ur local .htaccess and mod_rewrite

Check if mod_rewrite is enabled and your htaccess file is overriding

1) create a page phpinfo.php in your root call the phpinfo() function in the same

2) Now request this page from ur browser and look for a section called Loaded Modules.If it shows mod_rewrite....bingo its enabled from server

3) Next backup ur .htaccess default file and create a new one in that write

DirectoryIndex phpinfo.php

Now request ur website root from browser if you see phpinfo.php being called ur .htaccess is working in other words #allow override is enabled at httpconfig.