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 :)
Related
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]
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
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.
This question already has answers here:
Closed 10 years ago.
Possible Duplicate:
PHP function to get the subdomain of a URL
Im looking for an efficient way to tell if a subdomain exists within a URL.
The domain name will always be fixed e.g. mydomin.com, however if a subdomain is not set, I need to redirect.
One thought I had is that if there is more than one period (.), a subdomain is set, but im not sure how to implement this.
Many thanks.
EDIT: Sorry for not being too clear. I do not have a current solution, but looking at other posts I can see several examples of how to get the subdomain e.g.
array_shift(explode(".",$_SERVER['HTTP_HOST']));
But i do not want the subdomain, just to check if one exists. The subdomain could be anything.
You can get the hostname with parse_url. Then you break it down with explode():
function hasSubdomain($url) {
$parsed = parse_url($url);
$exploded = explode('.', $parsed["host"]);
return (count($exploded) > 2);
}
On google you can find really easily how to redirect someone.
I would rather use apache rewrite engine (or any webserver rewrite process) :
# .htaccess file
RewriteCond %{HTTP_HOST} ^yourdomin\.com$
RewriteRule (.*) http://sub.yourdomin.com/$1 [R=301,L]
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