Clean Url Codeigniter - url

I want to clear my url with codeigniter, I have these types of urls:
www.ggg.com/index.php/page/8/name.html
and I want to trasform these like
www.ggg.com/index.php/name.html or www.ggg.com/name.html
Is this possible modifying the file route.php?

Actually to get rid of the index.php you need to edit out the index.php file from config.php (in your config folder inside application).
.htaccess for clean urls:
RewriteEngine on
RewriteCond $1 !^(index\.php|images|robots\.txt)
RewriteRule ^(.*)$ /index.php/$1 [L]
and to get rid of the .html just eliminate that 'suffix' again in the config/config.php file.
That should be all you need, the .html ending is just for show
As far as turning something like page/8/name into name, I would think twice about how that would work, your page or 8 most likely mean something, so your name would have to have code making it unique. My guess is that page = 8 is the value, and the name is just for the friendly url look.

Edit the routes.php file and add the line:
$route['name'] = "page/8/name";
This is all explained in the docs: http://codeigniter.com/user_guide/general/routing.html
To remove the index.php you will need a .htaccess file. There is an example in the ci docs or google it and you will find loads of tutorials. I'm sure there are even some examples here.

Related

How do I stop a forward slash from being displayed at the end of a URL

I am running an Apache 2.4 webserver.
I have a file: http://192.168.0.12/test/index.html
Right now, if I access this file, it displays this in the address bar:
http://192.168.0.12/test/
All I want, is for it to instead display this:
http://192.168.0.12/test
Edit: I decided to get around the problem by instead storing everything I needed from the /test/ directory in the /test-content/ directory, and changing the /test/index.html file to just /test.html
Edit the .htaccess file and add the below rule:
RewriteEngine On
RewriteRule ^test$ /test1/ [L]

eliminate the extension html from a web page name

my first page in my website called index.html
when I put in the address bar :
http://websit/index.html it works
but
now my boss asked me that he wants the name just http://websit/index
how can I do that?
Standard web server behavior is to just load the "index.html" file as the root file of a path call. Meaning this:
http://websit/
Is the same as this:
http://websit/index.html
Doing something like this (below) will only cause more problems since it would seem that index is a path instead of a file:
http://websit/index
So any if you want to clean things up just make any reference to http://websit/index.html just http://websit/
If you are using Apache, then, you need to check if Mod Rewrite is enabled, and then, read articles about .htaccess and mod rewrite.
The solution:
Create a file with this name exactly .htaccess on root directory (where the index.html) is there. Then, copy this code (paste it inside the .htaccess file) and test it again using website/index without .html
#comments
RewriteEngine On
#base directory for this file, if its root, then its one /, if its test then its /test
RewriteBase /
#if the URL for the resource that requested is not exist as file
RewriteCond %{SCRIPT_FILENAME} !-f
#if the URL for the resource not exist as directory
RewriteCond %{SCRIPT_FILENAME} !-d
#then it anything types after the website/() redirect it to ().html
RewriteRule ^(.*)$ $1.html [NC,L]
#the ^ and $ used for matching whole string (from beginning to end)
#the () used for grouping matching strings
#the . used for matching any character
#the $1 represents the match group, for our example we used one () then its $1
[1] http://httpd.apache.org/docs/current/howto/htaccess.html

nginx url rewrite for CMS direct to /[user]/index.php

I am attempting to move to nginx...
I have an app running in apache using the following mod_rewrite commands:
RewriteCond %{DOCUMENT_ROOT}/%{REQUEST_FILENAME} !-f
RewriteRule ^/([a-z\-0-9]+)/(.*)$ /$1/index.php/$2 [E=USERKEY:$1,L]
The PHP backed we are using processes items in the form of:
/[USERKEY]/index.php/[module]/[action]/[etc...]
We want to pass every hit (where there is not a static file on disk) to the index.php file for processing in a format where:
http://www.myapp.com/bobsmith/rockstar/add?q=45678
would translate into:
/var/www/some_static_path/bobsmith/index.php/rockstar/add?q=45678
I know some CMS products do something similar and I located a lot of examples but we have this odd USERKEY payload (which is part of index.php's path) causing issues for my configuration. Additionally, I struggled dealing with the slash (/) after the index.php. The error logs would show:
"/bobmsith/index.php/login" failed (20: Not a directory)
When attempting to browse to: http://www.myapp.com/bobsmith/login
I have tried working with rewrite, if(s), different types of location regex, try_files, fastcgi_split_path_info... I cannot find the cocktail for success!
any/all help appreciated; thanks all!

This database URL structure?

I'm working on a database site now that has the URL structure:
example.com/f.php?id=12
I'd like to have
example.com/f/12
I see this all over the place (IMDb, Wikipedia..) but I can't work out how it's done.
Thanks for any help!
They are called vanity URLS and you can do it with htaccess.
http://www.youtube.com/watch?v=oqg6Chk6L7M
What you're looking for is mod_rewrite. It is defined in the .htaccess file located at the webroot of your server. Check out this article -> http://www.sitepoint.com/apache-mod_rewrite-examples/
Its done using Apache's mod_rewrite. For that example of yours you have to create a .htaccess file in the root folder with the following lines:
RewriteEngine On
RewriteRule ^f//?(.*)$ f.php?id=$1 [NC]
this will present "example.com/f.php?id=12" to "example.com/f/12" and "example.com/f.php?id=12/" to "example.com/f/12/". So it can do with a little teaking. But you get the idea. There are many examples out there, with a minute of googling I came across this.

Need to have either example.com/username or username.example.com, but how?

I'm almost finished developing my large project, however I would love it if I could make it so instead of having the users profile pages at: http://example.com/profile/username/USERNAME
(i'm currently using .htaccess to rewrite the GET data into forward slashes and profile(.php) being read as just 'profile' profile.php also parses the url correctly to retrieve the GET data)
But it would be some much better if I could do it so that it's like http://www.example.com/USERNAME (preferred) or http://www.USERNAME.example.com
Any ideas or resources?
Thanks,
Stefan
In your .htaccess in the root, add
RewriteRule ^/([^/]+)/? /profile/username/$1
This matches paths that don't include a slash (so no directories in the path) and suffixes the path to /profile/username/. The path can include an optional final slash.
(+1 for the comment about namespaces - it's a little dangrous having usernames in the root of your site. I've tried to limit the impact of this by only giving out the namespace comprising a single directory. Paths with multiple directories will be handled as normal.)

Resources