My current url is http://localhost/ci/ which is also set under config.php
but how do I open other pages in views without specifing index.php
http:/localhost/ci/Pages/view/login but not like this http:/localhost/ci/index.php/Pages/view/login
You should take a look at this
http://www.freewebmasterhelp.com/tutorials/htaccess/
you can do alot with .htaccess file
try putting this in your .htaccess file
RewriteEngine on
RewriteCond $1 ^(Pages|view|login|P[0-9]{2,8}) [NC]
RewriteRule ^(.*)$ /index.php/$1 [L]
Use application/config/routes.php file.
Add URL Routing definition is very simple with it.
See this link for more information: http://codeigniter.com/user_guide/general/routing.html
Related
http://localhost/rankeyiansacademy/course_details?id=digital-marketing-training
to
http://localhost/rankeyiansacademy/courses/digital-marketing-training
How can I change the url using htaccess in corephp?
I am hoping on your wamp/xampp rewrite module is on as required.
Then define $base_url = http://localhost/rankeyiansacademy in your config file or <base href="http://localhost/rankeyiansacademy/"> tag in html.
In your .htaccess file, add following code
RewriteRule ^courses/([A-Za-z-]+)$ course_details.php?id=$1
Then change the links in html like
If you define base tag, then use the following changes in html
Link
If you define variable in your config file,
Link
This one works for me. Hope that helps.
If you are looking for url rewrite, then you can use the Apache mod_rewrite module.
Apart from core php, if we use cms frameworks like wordpress, drupal, cakePHP, Zend, expression engine frameworks will implement url rewriting very easily.
Search engines like clean URLs pretty much and you should consider implementing it.
You can use this code:
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^.]+)$ $1.php [NC,L]
This can help you:
Write below code in your .htaccess file.
For detail page write: RewriteRule ^courses/([^/]+) course_details.php?id=$1 [NC]
For all course page: RewriteRule ^courses courses.php [NC]
Hope this can help you!!!
You can Use URL rewrite in htaccess File.
Put .htaccess file in main folder and use below code.It will read like if your URL http://example.com/index.php?page=search it will show like this http://example.com/search. This may help you to find solution
Code:
RewriteEngine on
RewriteCond %{THE_REQUEST} /product\.php\?cat=(search)
RewriteRule ^ /%1? [R=302,L]
RewriteRule ^(search)$ /product.php?page=$1 [L,QSA]
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 !
This is my current URL http://www.example.com/agent/index/$id,
and I want to change this http://www.example.com/demo_name(by agent name)
Please suggest your answer.
I'm not sure if I understand. But if you want omit the "index" in the url. You need to use a .htaccess file. This is a example:
RewriteEngine on
RewriteCond $1 !^(index.php|assets|robots.txt)
RewriteRule ^(.*)$ /directory/index.php/$1 [L]
I have a webpage which was built with core php, now its been updated to codeigniter mvc. Problem which i am facing is, users are trying to enter the old URL path
example: www.website_name/old_path
now since the mvc layout, it wont work and will get 404 error. i want to redirect the clients who enters www.website_name/old_path for the new one
www.website_name/index.php/new_controller/new_view.
Anyone please help me to resolve this issue.
Thank You!
first of all remove index.php config file.
Open config.php and do following replaces
$config['index_page'] = "index.php"
to
$config['index_page'] = ""
Then create HTACCESS file in application/ folder
having this code....
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]
</IfModule>
Now index.php is removed from your URl....
STEP 2) open application/config/routes.php file
Now here define your desired web URL
$route['mycontroller/(:any)'] = "mycontroller/user_detail/$1";
So,Your URL Will be ..
www.website_name/new_controller(or xyz)/
Here you can also change the controller name differently using routes So no one can get the exact name of controller/method name....To Do such customization refer this URL
http://www.codeigniter.com/user_guide/general/urls.html
As Sumit mentioned, you should use URL Routing for this.
In the routes file you can create a list of all the redirects that you want like so:
$route['old_path'] = "new_controller/new_view";
You can use 301 redirect for this type of issue.
Put this code in .htaccess
RewriteRule ^www.website_name/old_path www.website_name/index.php/new_controller/new_view [L,R=301]
or use 301 redirect of codigniter http://www.codeigniter.com/user_guide/helpers/url_helper.html
// with 301 redirect
redirect('/article/13', 'location', 301);
I would like to take requests for /somefolder/style.css and handle them with /somefolder/program.php
So, I put the following in my .htaccess file:
rewriteengine on
rewriterule ^style.css$ program.php?css=1 [R=302,L]
The result is that instead of redirecting to /somefolder/program.php, the server tries to redirect to:
/var/www/html/somefolder/program.php?css=1
How can I get rid of the /var/www/html/ in the redirect? I thought that since I just entered program.php in the .htaccess that it would default to the same folder.
Since this is a generic script that I will use in many places, I would like to avoid using rewritebase to specify the folder I'm in -- the .htaccess has to work in any folder without being modified.
Leave the R flag away and you will get an internal redirect:
RewriteRule ^style\.css$ program.php?css=1 [L]
Otherwise specify the full URL path you want to redirect to externally:
RewriteRule ^style\.css$ /program.php?css=1 [R=302,L]
Or for any arbitrary folder:
RewriteCond %{REQUEST_URI} (.*)/style\.css$
RewriteRule ^style\.css$ %1/program.php?css=1 [R=302,L]
I think the problem is that you are missing a ReWrite base statement.
Also the I would put the .htaccess file in the root directory of your site. That way you don't have to copy an .htacess file into every new directory you create. What if you want to change the name of your php file? You'd have to change every .htaccess file.
This is how I would redirect www.mydomain.com/orange/style.css to www.mydomain.com/orange/program.php?css=1 using generic rules:
RewriteEngine On
RewriteBase /
RewriteRule ^(.*)/style\.css$ $1/program.php?css=1 [L]