Dual URL Rewrite In PHP - php

Hello i am newbie so sorry in advance if i am asking a question in wrong manner
I am using CodeIgniter Framework .....i am stuck in URL rewrite .......
suppose example.com is my website.....URL rewrite is working in example.com/(here URL rewrite works)
for example
example.com/2014_12_12--->>link to page with data
example.com/2014_12_15--->> link to page with data
(Note its done with url rewrite and it is working fine)
Now i want that i modify my URL with some sort of texts....like that
example.com/2014_12_12--->>link to -->>example.com/random text from array/2014_12_12
Random text that i want to put it is just for optimization/seo purposes it has no link with data
Is it possible ? I'll appreciate :-)
Sorry for any inconvenience

Make below changes in application/config.php file
$config['base_url'] = 'http://'.$_SERVER['SERVER_NAME'].'/Your Ci folder_name';
$config['index_page'] = '';
$config['uri_protocol'] = 'AUTO';
Make .htacces file in your root directory using below code
RewriteEngine on
RewriteCond $1 !^(index\.php|resources|robots\.txt)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L,QSA]

Related

Codeigniter base_url in plesk

Recently I uploaded a website which created using codeigniter framework into plesk. Inside the c-panal I changed the document root into httpdocs/public_html/cliftonhotel.ae, and I uploaded the files using FTP into the same. I changed the base_url into
$config['base_url'] = 'http://cliftonhotel.ae/';
The problem is if I enter the web address it loads fine(The home page), but the other menus are not working, they shows a 404 page not found error.
[http://cliftonhotel.ae/][1]
this is the site. What is the solution, thankyou.
Do some changes, hope it's work
// .htaccess file
RewriteEngine on
RewriteCond $1 !^(index\.php|public|\.txt)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?$1
// config.php
$config['index_page'] = ' ';
It seems that the links you have created are missing index.php
For example: http://cliftonhotel.ae/index.php/home/about works
but http://cliftonhotel.ae/home/about does not.
So you have to either change the links or edit your .htaccess for url rewriting

Hiding controller and method from the URL but show only title name

I looked at the suggested answer(possible duplicate as stakoverflow says). It provided help but didn't solve the problem as it won't help create clean URL as per my needs. It has controller as part of the URL which I don't want to see as mentioned below.
I am developing a tutorial site in Codeigniter, and looking for a way to generate SEO friendly URL like
www.crdlabs.com/how-to-use-multidimensional-arrays
instead of
www.crdlabs.com/home/index/how-to-use-multidimensional-arrays.
Can anyone share his ideas? Thank you
First you need to hide the index.php from URL so create the .htaccess file on the root folder and add this code
.htaccess
DirectoryIndex index.php
RewriteEngine on
RewriteCond $1 !^(index\.php|(.*)\.swf|forums|images|css|downloads|js|robots\.txt|favicon\.ico)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ ./index.php?$1 [L,QSA]
Then open the routes.php file in the application/config/routes.php location
and add this
$route['how-to-use-multidimensional-arrays'] = 'home/how-to-use-multidimensional-arrays';
This will work as URL as SEO friendly
Add this to ur root .htaccess file :
RewriteRule ^(.*)$ index.php?title=$1 [NC,L,QSA]
Then in ur index.php get the title $title = $_GET['title'] and do what ever you like with it like do a query in ur database and return data based on the title !

Rewriting .htaccess to remove index.php with alias url on codeigniter

I have an issue with .htaccess codeigniter on our website (www.jp.com => first project)
I just recently built a new project and i set and accessed by an aliased link. (www.jp.com/pt => second project).
A path looks like this :
first project : /var/www/jp
second project : /var/www/pt
The problem, if i access this url : "www.jp.com/pt" it's works,
but.. if i access others controller, e.g: "www.jp.com/pt/news" where i'm not set a controller as a default controller, the page shown 404 not found.
And then,i try using index.php like this, "www.jp.com/pt/index.php/news" It's works..
Can anyone help me to fixing this ? i'll can access my alias link without index.php
I using CI 2 & PHP 5.3
Here is my code (mixed from many references :D )
Current .htaccess :
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_URI} ^system.*
RewriteRule ^(.*)$ /index.php?/$1 [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond $1 !^(index\.php|images|robots\.txt|public)
RewriteRule ^/(.*)$ http://www.jp.com/$1 [NC,L,R=301]
My Config.php :
$root = "http://".$_SERVER['HTTP_HOST'];
$root.= str_replace(basename($_SERVER['SCRIPT_NAME']),"",$_SERVER['SCRIPT_NAME']);
$config['base_url'] = "$root";
$config['index_page'] = '';
Thank you...
The .htaccess RewriteBase in the codeigniter second project directory should say /pt/
RewriteBase /pt
Otherwise the rewrite to index.php ends up going to first project router.

CodeIgniter .htaccess rewrite not working on Live Server

I have a little problem with Code Igniter project, I have a .htaccess file to rewrite the index.php. It works great if I put my projects on Local Server. I am using WAMP Server. But now I have uploaded it on Live Server for example (godaddy,00webhost). And it is showing error :
404 Page Not Found.The page you requested was not found.
My .htaccess is here :
RewriteEngine on
RewriteBase /directory_name/
RewriteCond $1 !^(index\.php|(.*)\.swf|forums|images|css|downloads|jquery|js|robots\.txt|favico​​n\.ico)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?/$1 [L,QSA]
and my config.php setting is here:
$config['base_url'] = 'http://example.com/directory/' ;
$config['index_page'] = '';
$config['uri_protocol'] = 'AUTO';
I have tried many solutions on web but not enough lucky to find one who helps me. I am stuck since 3 days. Anyone Help me.
If you are trying to host the website in a subfolder, make sure you enter the correct info in your htaccess and config:
Change RewriteBase /directory_name/in htaccess to RewriteBase /ci_foam/
Change $config['base_url'] = 'http://example.com/directory/' in your config to $config['base_url'] = 'http://php0713061.herobo.com/ci_foam/'
You always need to make sure these values matches your current server setup.

how to redirect a URL according to get variables in URL

I am trying to change my website URL according to get variables so that I can increase the security of my website.
For example I want to change my address, this is my htaccess file:
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /category.php?cat_id=$1&mode=full&start=$1
And my website URL is:
http://joinexam.in/category.php?cat_id=17&mode=full&start=36
I want to convert this URL to:
http://joinexam.in/category/1736
where cat_id = 17
and start= 36
So it will become 1736 after the category.php page, I am trying to do it by using .htaccess file.
Here I want to take both cat_id and start as get variable, then according to these get variables, I want to change the URL of my website.
Can anyone explain the correct way to achieve this?
.htaccess
This forwards every URL to index.php.
Options +FollowSymLinks
RewriteEngine On
RewriteCond %{SCRIPT_FILENAME} !-d
RewriteCond %{SCRIPT_FILENAME} !-f
RewriteRule ^.*$ ./index.php
PHP
Get the "original" URL inside index.php:
// this gives you the full url
$request_uri = $_SERVER['REQUEST_URI'];
// split the path by '/'
$params = split("/", $request_uri);
Then you might route based on these $params.
As a good and fast router lib i suggest: https://github.com/nikic/FastRoute
By using this, you don't have to mess around with htaccess regexp stuff and can keep things at the PHP level :)

Categories