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

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

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

How can I get the full URL in PHP, not just part of it? [duplicate]

This question already has answers here:
Can I read the hash portion of the URL on my server-side application (PHP, Ruby, Python, etc.)?
(12 answers)
Get the full URL in PHP
(27 answers)
Closed 9 years ago.
This is my current URL structure
http://wp.raddyx.in/consultant-dietitians/staff-single/#Fiona%20Brown
I am using echo $url=$_SERVER['REQUEST_URI'];
However it displays /consultant-dietitians/staff-single/ only, where I want to fetch the full URL.
Use $_SERVER["SERVER_NAME"] to get the host name wp.raddyx.in
Use $_SERVER["HTTPS"] to check for http vs https.
You might need $_SERVER["SERVER_PORT"] too and some other misc things that can appear in a URL (like PHP_AUTH_USER)
You can not get the hash part of the URL (#Fiona%20Brown) since hashes are client-side only. They are not sent to the server.
Relevant manual page: http://php.net/manual/en/reserved.variables.server.php
Use $_SERVER[HTTP_HOST]:
$url = "http://$_SERVER[HTTP_HOST]$_SERVER[REQUEST_URI]";
echo $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'];

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 can get the current path in PHP [duplicate]

This question already has answers here:
How to get URL of current page in PHP [duplicate]
(5 answers)
Closed 9 years ago.
How can I return the path of the current page including whats after ?
So for example I am this link
localhost/site1/index.php?view=10&user=5
I want to return this value "index.php?view=10&user=5"
How can I do that using PHP?
I thought $_SERVER['SCRIPT_NAME'] do this but SCRIPT_NAME is returing index.php
$_SERVER['QUERY_STRING']
and
$_SERVER['REQUEST_URI']
request uri will give you full uri, you can manipulate it to get the last path
as #Mathieu Imbert said, get curious. Inspect everything $_SERVER gives you either by var_dump or by reading documentation i linked to in a comment

How to pass # in url params? [duplicate]

This question already has answers here:
Closed 11 years ago.
Possible Duplicate:
# in url getting ignored in php 5.2
I have following link on webpage. Here I am sending return(/profile?id=6#contacts) as url param to return back after operation complete. But it is sending only /profile?id=6 to verify.php script.
http://example.com/verify.php?id=1&sessionId=6&return=/profile.php?id=6#contacts
I know that hash value is not passed to server but I want to know that is there any way to pass compelete return param to server with # value.
Thanks
You need to urlencode() the entire return parameter.

Categories