Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 7 years ago.
Improve this question
I'm wondering how sites like Pastebin and Twitter pass (what I assume to be) variables via the URL.
For example, take a Pastebin URL. It has the format of http://www.pastebin.com/<PASTE_UID>. I'm wondering how they parse the UID without the server trying to treat it like an actual page. I can't imagine they generate individual files for each post.
I know this is most likely a combination of mod_rewrite and parsing the variable from the URL on the backend to extract the variable, but I'm at a loss on how to do it.
As you said, you can use apache mod_rewrite, i.e.:
Create an .htaccess file on the root of your website with the following content:
RewriteEngine on
RewriteRule ^uid/(.*)$ /uid.php?uid=$1 [NC]
If, for example, the url is http://yoursite.com/uid/123456, apache will send the value 123456 via $_GET request to uid.php, you can get the uid value using:
<?php
if(!empty($_GET['uid'])){
$uid = $_GET['uid'];
//123456
}
?>
Related
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 2 years ago.
Improve this question
I am currently writing an app where you can add a comment to a post based on IdTicket.
<td>Comments</td>
I am passing the Id value in my URL which is a part of the table. It is a dynamic value, different for every ticket. I am using $_GET['IdTicket'] on the comment.php page to get the id and based on that write a comment.
Is there a way to rewrite that link in htaccess? It would be perfect to hide everything or just make it prettier. And how would it look applied to that table?
Sure that is possible. And there are already countless examples for this...
You need to change the reference you hand out in your spplication logic:
Comments
And you need to take care to internally rewrite the incoming request to the actual resource again:
RewriteEngine on
RewriteRule ^/?comments/(\d+)$ /comments.php?IdTicket=$1 [QSA,END]
Obviously the rewriting module needs to be loaded. And if you want to use distributed configuration files (instead of the real host configuration inside the http server) you also need to have enabled the interpretation of those for host and location.
Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 6 years ago.
Improve this question
I am working on some sort of blogging platform in php with a nice material design lite frontend. However I have a page that dynamically loads the content, it works fine in the root directory, but not in my admin directory. I hope you can spot some kind of error/typo in my code, I know the error is in the menu-start file, since disabling it enables loading.
Here is the page that loads the code
and here is the menu-start page
If you need any other code, please ask
You're using relative links for include, which will mess up when you start changing directories. Use a pseudo-absolute path with DOCUMENT_ROOT. Be sure to use this for all of your includes.
<?php include $_SERVER['DOCUMENT_ROOT'].'/menu-start.php'; ?>
Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 8 years ago.
Improve this question
I'd like to set my Apache server up so that when someone visits, say, site.com/kittens/ (or site.com/kittnes/index.php), they would actually get to view site.com/certainpage.php. Of course I could copy certainpage.php to /kittens/ and rename it index.php, but it seems like a really lame way to do it.
Any help? I feel like this shouldn't be something too complex.
You can use a rewrite rule to keep the URL the same but swap the contents out for that of another file like so:
RewriteEngine On
RewriteRule ^kittens/(index\.php)?$ /certainpage.php [L]
Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 8 years ago.
Improve this question
I use a code to set the URL as:
http://domainname.com/user
The problem is that I use some masks in my .htaccess, so what we see in the URL is not always the real path of the file.
What I need is to get the URL, what is written in the URL, nothing more and nothing less—the full URL.
I need to get how it appears in the Navigation Bar in the web browser, and not the real path of the file on the server.
You need to simple check in PHP what's the value of $_SERVER['REQUEST_URI']
or substr($_SERVER['REQUEST_URI'],1) if you want to remove leading slash
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
i want to know is there is a possibility to build a code/script etc (never mind in which prog language) that will do the next thing. for instance if my main domain is www.alex.com
so when i will go to www.alex.com/xxxyyyzzz it will generate automatically a web page with some information(templete for all of the non excisting pages?) even if there is no "xxxyyyzzz" in the DB. in other words i need some kind of page generator when sublink is being requested.
thanks.
Have you heard about frameworks?
A framework can do what you are looking for. Depending on the url, they can generate your page.
Here is a great one - codeigniter
Another one - yii.
If using PHP and Apache:
Use a .htaccess file similar to this:
RewriteEngine On
RewriteCond %{REQUEST_URI} !.*\.(ico|gif|jpg|jpeg|png|js|css|woff|ttf|svg|eot)
RewriteRule ^(.*) index.php?route=$1 [QSA]
This will mean if a user goes to www.alex.com/xxxyyyzzz, apache will internally route this to www.alex.com/index.php?route=xxxyyyzzz
In a PHP file you can find the route using something like this:
if (isset($_GET['route']))
$route = filter_input(INPUT_GET, 'route', FILTER_SANITIZE_SPECIAL_CHARS);
and then based on different values include a different file. Don't do something like include $route; as someone could request any file they wanted. You could have an array with possible values and if it matches the array key then include the the value of the array at that key.