Codeigniter rewriting URLs replace question marks with slashes - php

I'm developing a web using PHP Codigniter,
I want to make my URLs look nicer,
For example I want this URL:
http://localhost/mlotfy/freelancing/quiz/view_quiz?id=25
To look like this:
http://localhost/mlotfy/freelancing/quiz/25
I've tried this Rewriting rule in .htaccess file but didn't work out(404 page not found)
RewriteRule quiz/([0-9]+) quiz/view_quiz?id=([0-9]+)

Try this
RewriteRule ^quiz/([0-9]+)/?$ quiz/view_quiz?id=$1 [NC,QSA,L]

Related

Neep help rewriting php query string to slashes in the URL

I would like to simplify the url on my website forum,
how can i rewrite this
forum.php?topic=10
to this
forum.php/topic/10
Sure you mean forum.php?topic=10 to forum.php/topic/10? I assume you mean the other way
What you need (untestet):
RewriteRule ^/(.*).php/(.*)/([0-9]+)$ $1.php?$2=$3
But it would be better to make it this way:
RewriteRule ^/(.*)/(.*)/([0-9]+)$ $1.php?$2=$3
Then your Url is only forum/topic/10 without .php
Please take a further look into this:
http://www.addedbytes.com/articles/for-beginners/url-rewriting-for-beginners/

how to use htacces rewrite code for 3 diffrent files

i trying to make 3 diffrent files diffrent url i use currently below code whis is work perfect for me.
RewriteRule ^([a-zA-Z0-9-/]+).html$ file.php?file=$1
and i feel i need more urls for 2 other files and i change this code as below but this not work it change url fine but it not redirect me to contact.php its redirect to file.php as above code work.
RewriteRule ^([a-zA-Z0-9-/]+).html$ contact.php?contact=$1
so i need to help for make 3 files diffrent urls.
How is apache supposed to tell the difference between a request that's supposed to go to file.php or a request that's supposed to go to contact.php? They look completely identical. You'll have to preface it with something unique, like:
RewriteRule ^file/([a-zA-Z0-9-/]+).html$ file.php?file=$1 [L]
RewriteRule ^contact/([a-zA-Z0-9-/]+).html$ contact.php?contact=$1 [L]
So the URLs will look like:
http://example.com/file/foo.html
http://example.com/comtact/bar.html

Multiple vanity URLs for different php files?

I am trying to build a site which has the following pages which needs vanity urls,
account.php
questions.php
profile.php
I need to display
www.mysite.com/account?req=settings
www.mysite.com/account?req=questions
www.mysite.com/account?req=answers
as following
www.mysite.com/account/settings
www.mysite.com/account/questions
www.mysite.com/account/answers
And for the other files I need the following,
etc:-
www.mysite.com/questions?id=0484684
As
www.mysite.com/questions/0484684
And
www.mysite.com/profile?id=123456
as
www.mysite.com/profile/123456
Would anyone help me because I really need to make this possible.
I would like to remove the .php extention from the url too.
I like to say that I have no experience in htaccess files.
Thanks for the help, it worked !!!
In your .htaccess file, add these rules:
RewriteEngine on
RewriteBase /
RewriteRule ^account/([^/\.]+)/?$ account.php?req=$1 [L,NC,QSA]
RewriteRule ^questions/([^/\.]+)/?$ questions.php?id=$1 [L,NC,QSA]
RewriteRule ^profile/([^/\.]+)/?$ profile.php?id=$1 [L,NC,QSA]
You should be able to add new rules based on how these work if you need them in the future.
You'll want to use a .htaccess file combined with PHP for complex manipulations like that, I wrote an article on re-writing URLs after asking a similar question on SO:
http://tomsbigbox.com/elegant-url-rewriting/

Wildcard Url Pattern using htaccess

i am looking for htaccss code. i want like if some one vist
domain.com/folder/ver-234123.html
domain.com/folder/ver-4234234.html
domain.com/folder/ver-kahsdkf.html
so it all baiscally open domain.com/folder/index.php
i will randomize the number/digits after ver- via php.
You want to use mod_rewrite.
Assuming "/folder" actually exists and this .htaccess would be within it.
This should be a fairly simple rewrite. Something like:
RewriteEngine on
RewriteRule ^/?ver-[a-z0-9]*\.html index.php [L,QSA]

Custom URL with PHP

I have a small question to ask. Is it possible, via php or htaccess, to change a url like: miodominio.com/users.php?idu=x into something like miodominio.com/username ?
I want it to be Facebook style...Where "username" is the username chosen by idu = x.
There are multiple ways to solve this problem, but here's one that always suits my needs.
Guide all your URL requests through the index.php first and resolve the request in your PHP code second.
1) Use an .htaccess file to direct all URL's through index.php. You'll find one way here by the CodeIgniter framework and a more advanced explanation here. I recommend the CodeIgniter .htaccess guide first if you're inexperienced with .htaccess.
2) Second, use the $_SERVER variable in PHP to extract the URL. Probably with the help of the $_SERVER['REQUEST_URI'], you'll find '/username/' which you can then use to extract the user's data and serve it to them.
Good luck and beware of URL injections using this method.
You need to use apache's mod_rewrite for this. It can translate miodominio.com/username to miodominio.com/users.php?idu=x. There are some good guides about this which are easy to find with Google.
You can try to use this mod_rewrite pattern (add it to the .htaccess):
RewriteEngine On
RewriteRule ^([a-zA-Z0-9_-]+)$ users.php?idu=$1
RewriteRule ^([a-zA-Z0-9_-]+)/$ users.php?idu=$1
you have to write a clean URL in your .htaccess file like :
RewriteEngine On
RewriteRule ^([a-zA-Z0-9]+)/$ users.php?idu=$1
Put the following in your .htaccess
RewriteEngine on
RewriteRule ^([a-z0-9_-]+)/?$ /users.php?idu=$1 [NC]
The [NC] will make it case-insensitive, if you accept only lowercase username, remove the [NC] from the last.

Categories