Shortened url redirect? [closed] - php

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]

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.

Hide dynamic page "movie.php?id=10" from my PHP website's URLs and replace spaces with hyphens [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 5 years ago.
Improve this question
My website's URLs are as:
"/movie.php?id=10 Rangoon (2017)"
Spaces are converted to %20 by web browser.
But I want the simple URL like this:
"/Rangoon-(2017)"
How Can I do that?
My website is developed in PHP and all data of my website is placed on MySql Database and "movie.php" page retrieves the data from MySql Database.
Well, that's not a simple one, you'll have to make many updates :
generate an url for each of you movie pages (By the way, don't use parenthesis in an url, in your example the url should be something like rangoon-2017). You may use my method
seoUrl
store this url somewhere in your database
Decide on an url scheme, like movie/title-of-your-movie
When displaying a link, display the url scheme
create an .htaccess file which rewrites movie/whatever to movie.php?url=whatever
On movie.php, retrieve your movie information from the url and not the id
Additional thoughts :
you'll have to make sure each movie has an unique url. Adding the year is a good idea, since I doubt two movies will have the exact same title and year.
also, make sure your urls are unique in the database (And indexed, since you'll search from them)
why the prefix movie/ on the url ? Simply because if you don't create it, you'll find more difficult to redirect other type of pages to the correct file.

How to prevent direct viewing of html files using htaccess? [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 6 years ago.
Improve this question
I would like to prevent users to view the contents of all html files.
Example:
website.com/join/view_template.html (and it will display all the codes including the smarty)
I would like them to be redirected to 404 page if they do this.
I'm not sure if this is possible in htaccess.
You can use the following line in htaccess :
RedirectMatch 404 ^/.+\.html
This will return 404 not found error for all .html files.
Try it like this although I didn't try it for now,
RewriteEngine On
RewriteRule \.html - [R=404]

Echo'd links showing after my web address [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 9 years ago.
Improve this question
Just a quick question obviously has a simple solution, however I am unable to find it...
Would anyone be kind anough to point me in the right direction on why this piece of code is showing up after my directory in the new tab...
echo "<td><a href='$row[link_address]' target='new'>" . $row['link_address']. "</a></td>";
Once the new tab opens it is echo'ing the link after my web address, for example www.mysite.com/$row['link_address'] I am obviously looking for this to be just the link and not a forward slash after my directory.
Any help would be much appreciated.
Thank you!
Absolute links (where the entire URL is in the link) need to start with the protocol part of the link (eg http:// or https://).
Otherwise, the browser assumes the link is to a directory called abc.com on your domain, rather than to the abc.com domain.

Categories