Change displayed url with htaccess [duplicate] - php

This question already has answers here:
Reference: mod_rewrite, URL rewriting and "pretty links" explained
(5 answers)
Closed 1 year ago.
Hi guys I want to change this url: https://example.com/game.php?games=Final-Fantasy-XIV/
to this: https://example.com/game/Final-Fantasy-XIV/

For the next time, please provide, what you already tried and do your amount of own research. However, this should work:
RewrtieEngine On
RewriteRule ^game/(.*)/$ /game.php?games=$1 [L,NC]

If you display url by name (text) then it should be as folowing
RewrtieEngine On
RewriteRule ^([a-zA-Z0-9_-]+)/$ game.php?games=$1 [L,NC]
If you display url by id then it should be like this:
RewrtieEngine On
RewriteRule ^game/(.*)/$ game.php?games=$1 [L,NC]

Related

What is URL Morphing? [duplicate]

This question already has answers here:
Reference: mod_rewrite, URL rewriting and "pretty links" explained
(5 answers)
Closed 6 years ago.
I want to pass a variables from one php file to other php file by GET method only without showing in URL.
for example: http://www.mysite/test.php?user_id=1
Instead of this just need URL should be like http://www.mysite/test
How it can be possible?
Note: I am aware about $_SESSION, $_POST but all of them are also will show URL like test.php, that I do not need actually..
This should solve your purpose:
RewriteEngine On
RewriteCond %{QUERY_STRING} ^page=1$
RewriteRule (.*) $1? [R=permanent]
Use this for further reference: remove query string from end of url URL using .htaccess

Convert a query string to user friendly URL [duplicate]

This question already has an answer here:
URL Rewriting of a query string in php [duplicate]
(1 answer)
Closed 8 years ago.
how to convert this url
http://www.example.com/category_listing.php?city=Bangalore&search=Astrology&submit=Go
into
http://www.example.com/Bangalore/Astrology
Here is the easiest way to do it.
First, turn on mod_rewrite in .htaccess
Like this:
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . category_listing.php
Next, you need to parse the query string in category_listing.php
For example:
$query = explode('/', $_SERVER['REQUEST_URI']);
$city = $query[0]; // 'Bangalore'
$search = $query[1]; // 'Astrology'
Play with array indices, it may be 1 and 2 instead of 0 and 1 depending on your server settings.
That's all it takes!

How to make simple url rewriting [duplicate]

This question already has answers here:
URL rewriting with PHP
(5 answers)
Closed 8 years ago.
I'd like to know how to make a url rewriting?
Basically, if I go to www.site.com/announce/123456 I'd like to actually use the page www.site.com/annouce.php?id=123456
I can't get any simple documentation about it.
Thanks
Based on Gecko's answer I made a .htaccess which works fine :
Options +FollowSymlinks
RewriteEngine On
RewriteRule ^announce/([0-9]+)$ announce.php?id=$1 [L]
You must use mod_rewrite into .htaccess file like this :
RewriteEngine On
RewriteRule ^/announce/([0-9]+)$ announce.php?id=$1 [QSA]
[QSA] flag allow you to pass other arguments in your url, like this :
www.site.com/announce/123456?arg2=test
Have fun :)

Variables as www.example.com/var1/var2/ [duplicate]

This question already has answers here:
URL rewriting with PHP
(5 answers)
Closed 8 years ago.
I want to make something like:
www.example.com/var1/var2/
where I can take the value of the variables, but it also need to be compatible with GET like:
www.example.com/var1/var2/?feat=1234
How can I do this?
Thanks
<?php
$url = $_SERVER['REQUEST_URI'];
$url_splitter = explode('/', $url);
echo '<pre>';
print_r($url_splitter);
?>
Now you can access the variables by taking $url_splitter[0], $url_splitter[1],....
Check out symfony or codeigniter
The documentation will explain how to do a mod rewrite to get the url you want.
A partial re write can be done in this way (have not tested)
http://forums.devshed.com/apache-development-15/partial-mod-rewrite-454669.html
RewriteRule ^([^/]+)/([^/]+)/?$ index.php?var1=$1&var2=$2 [QSA,L]
That should turn a url like /foo/bar/?var3=baz into /index.php?var1=foo&var2=bar&var3=baz I am not sure it'll work though because I don't know how the regexp in the mod rewrite works.

Make filename including extension not show in the URL? [duplicate]

This question already has answers here:
Reference: mod_rewrite, URL rewriting and "pretty links" explained
(5 answers)
Closed 8 years ago.
I would like to have the filename including the extension not show in the URL when requesting it. And I am wondering is this possible with a PHP & Apache combination - and how can this be achieved?
For example, this:
www.domain.com/folder/filename.php
Should become, this:
www.domain.com/folder/
Any suggestions?
The following rule in an .htaccess file will work:
RewriteRule ^folder/$ folder/filename.php [L]
A more dynamic rule that will rewrite folder/<filename> to folder/filename.php would be:
RewriteRule ^folder/(.*[^\.php])$ folder/$1\.php [L]
Reference
mod_rewrite
An In Depth Guide to mod_rewrite for Apache

Categories