php profiling with names in the url "mod_rewrite" [closed] - php

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
am creating a website for a company in php i need to create to every member his profile page
like facebook's url
www.mywebsite.com/my.name
not like this:
www.mywebsite.com/?profile_id=65497
any ideas ??

I asume you are aware that this can only be done if you have some source that maps ids to names. mod_rewrite can look up strings in a lookup table and use the result in a substitution.
For example suppose you have a file that contains the name to id mappings.
# Mapping of names to UserIDs
Bill.Gates 100
Barack.Obamaq 101
Arsan.Gamal 102
You could then add the following to your apache config:
RewriteEngine On
RewriteMap UserIDs txt:/path/to/userids.txt
RewriteRule /(.*) /?profile_id=${UserIDs:$1|NOTFOUND} [PT]
Now when a request comes for /Bill.Gates the part after the / is captured in a regex back reference, and used to look up a value in userids.txt. This value is than used in you substitution.
There are other possibilities. If your usernames and IDs exist in a database you can use a database query in a RewriteMap. More info on what you can do with RewriteMaps, and how to do it can be found in the manual here:
http://httpd.apache.org/docs/2.4/rewrite/rewritemap.html

Related

PHP htaccess URL rewriting [closed]

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.

Simplest Routing For URL Queries [closed]

Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 2 years ago.
Improve this question
I'm stuck trying to figure out the best approach to my problem. I want to pass query params with a / than a ?.
So for example, instead of:
https://example.com/search.php?q=test
It'd be:
https://example.com/search/test/
I'm not using any PHP framework. How can I reach my goal?
You could do this with your .htaccess file.
For that you need to write in your .htaccess:
RewriteEngine on
RewriteRule ^search/([A-Za-z0-9\-]+)/?$ search.php?q=$1
The first line activate your RewriteEngine, so you can write RewriteRules as much you like.
In the second line you define your first RewriteRule:
In the URL it need to be search/([A-Za-z0-9\-]+)/.
That means, you only allow the characters inside the square bracket.
Then you redirect to your wanted script, in this case its search.php with the GET Parameter.
It's also possible to do this with more parameters or much more. For that you should google maybe "htaccess Explanation".
Better try php router and dont waste the time for rewrite !!!
And test nginx server it is awesome.

Shortened url redirect? [closed]

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 8 years ago.
Improve this question
I need help to get this done.
My webpages have formatted urls in this pattern: "http://qifu.us/index.php?page=item&id=4" for example - if there are more pages, only the last page id number will be different.
I want to get this part "index.php?page=item&id=" out, and shortened like "http://qifu.us/s4", when a user input the shortened url into to address bar, it will be directed to the right page, which is the true url.
I am thinking to save the STATIC part "index.php?page=item&id=" into a string variable, and append the DYNAMIC page id - which is 4 in this example, then use Javascript or PHP to direct to the right page. But I don't know how the steps, pls help. Thanks.
Actually an htaccess will be very good for this purpose.
For urls like http://qifu.us/s4 do the following: Create a file with name .htaccess and place at your root directory with the following content.
RewriteEngine On
RewriteRule ^s([^/]*)$ /index.php?page=item&id=$1 [L]

How to check login nave VS a field from database table in PHP? [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 9 years ago.
Improve this question
How can I figure out the login information for a user.
I want php to return domain\username for the windows then i will do a check in the database if it exists or not if it exists then it is validated.
In ASP.NET this function Page.User.Identity.Name.ToString() does exactly what i need but i need this is PHP
How can i do this is PHP? I heard of LDAP but I can't get it to work and I am not sure if LDAP will do the trick.
Thanks
If you want http://domain.com/username
you must have to use .htaccess file. read more about htaccess
Edited
after login, just store username to one variable and say it $username, now pass that username to your index.php file like...
index.php?username=$username
rewrite this URL via htaccess.
RewriteEngine On
RewriteRule ^([^/]*)$ /index.php?username=$1 [L]
now you can access it domain.com/username

PHP: Two basic questions about URL [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
Question 1
www.example.com/?do=blah
How do you get it to work without index.php? Any examples?
Question 2
www.example.com/news.php?blah
This link doesn't show the same result as news.php, but shouldn't we be using news.php&blah=value for example? What does the string after ? stand for? Shortened version of GET variables or an entirely different thing?
Question 1
As long as index.php is your default and you have it present in your root folder then you only need to have www.domain.com/?querystring=value
Question 2
? is the beginning of a querystring parameter. It should be used for the first one.
& is for every querystring parameter after that.
index.php?querystring1=value&querystring2=value&querystring3=value and so on.
You can configure a URL rewrite using .htaccess for both of 'em.
RewriteEngine On
#for question 1
RewriteRule ^(.*)$ index.php/$1 [L]
#another example for question 2
RewriteRule ^news.php\?(.*)$ news.php?blah=$1 [L]
The first example will capture everything and redirect the user to the index.php file. So if the user tries to access domain.tld/abc they'll actually be accessing domain.tld/index.php/abc
As for the second example, it will grab the everything that is part of the query string (a better Regex might be needed). Basically, it'll turn news.php?value to news.php?blah=value
I don't entirely understand your second question, but the answer to your first question is that you need to specify a different default directory index on your webserver. Assuming you are running Apache, find this line in the httpd.conf file:
DirectoryIndex index.html index.php ...etc
and change it to:
DirectoryIndex your_preferred_default_page.php
For your second question, the question mark is not shorthand, it marks the beginning of a query string... it's used as a cue to treat futher strings as GET keys and values.

Categories