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

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

Related

Change displayed url with htaccess [duplicate]

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]

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

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.

How to rewrite URL with hash in it? [duplicate]

This question already has answers here:
Closed 10 years ago.
Possible Duplicate:
Can PHP read the hash portion of the URL?
I use hash in my url like this,
http://mysite.com/home/#/page/manage/
I want to get /page/manage/ via $_REQUEST so I try url rewrite mod like this below,
RewriteRule ^home/#/([a-zA-Z0-9\-]+)/([a-zA-Z0-9\-]+)/?$ index.php?url=home&system_url=$1&system_name=$2 [L,QSA]
system_url=$1&system_name=$2 are not sent to $_REQUEST of course.
How can I get the result below via $_REQUEST?
array([url]=>'home',[system_url] => 'page',[system_name] => 'manage')
The fragment part of a URL (the part after #) is not actually sent to the webserver.
Thus, it is not possible to use rewrite to change it

Categories