A specific htaccess inquiry [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
After a bit of research I think its better if I ask for help to a specific problem, because I think if I am to learn the skills needed, I'd be taking on another language, and I can't get into the details of htaccess and regular expression at the moment, hopefully someday.
What I have now in URL is (localhost/site/controller/function/$arg1)
What information do I need to place into the htaccess so the controller and function isn't displayed. But the end result is (localhost/site/$arg1).

I think, this doesn't really make sense. As stated in the comments, you can use mod_rewrite to send your shortened URLs to the controller, but controller and function need to be static. So having a separate function doesn't really help, controller should be enough.
One thing you could do is selecting the RewriteRules in your .htaccess depending on the $arg1 using for example RewriteCond. That way you could send different URLs to different controllers. It depends on your URL structure if this is feasible.

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.

How to make a dynamic timeline using bootstrap? [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 7 years ago.
Improve this question
I'm trying to make a dynamic timeline like facebook that can post pictures and descriptions with dates using mysql php for database. I put bootstrap because I like their design, and it's easy to use.
My problem is i don't know where to begin or where do I study it.
Here's an example of what I'm talking about:
Any suggestions?
What a generic question... this seems to me an impossible question to answer but maybe you need just some little advices to begin studying the right languages which you can use to achieve what you want.
First of all please provide an image of what you want to do and more important the fundamental languages that you have to know are HTML (obviously), CSS, Javascript and PHP for some server side script.
Talking specifically about your problem, here is where you can see some open examples with well commented code that allows you to understand everything.
http://www.jqueryrain.com/2015/05/ideabox-jquery-timeline-news-ticker/
http://www.jqueryrain.com/2014/11/vertical-timeline-css3-jquery/

Rewrite URL of php page to be png [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 7 years ago.
Improve this question
I am thinking of making a tool for my own development similar to placehold.it. I would like to have something like this.
<img src="url.com/picture.php?id=51"/>
to be
<img src="url.com/51.png"/>
Any ideas?
Edit: Even though I have used Stack Overflow to answer questions and looks stuff up, this is my first time asking a question. This is a bit crazy. Apparently it isn't detailed enough. I just thought that less is more sometimes and it seemed to make sense.
Anyway... I am simply wondering if you can make a php page behave like a image. I would like to be able to pass data to my php page, do stuff with the variables, then return content in the form of an image. For example:
This
<img scr="url.com/picture.php?color=blue"/>
Could be seen by the browser as
<img scr="url.com/blue.png"/>
My guess is it needs to be done with a rewrite rule. I have done a little work with those in the past for making pretty urls (www.example.com/some/random/url vs example.com/someRandom.php?a=url) but I wasn't sure if changing the type from php to png would work.
Hopefully this will make sense now.
You can do that using .htaccess.Here is the RewriteRule.
RewriteEngine On
RewriteRule ^([0-9]+).png$ /picture.php?id=$1 [L]
Thanks.

Is it better practice to do a 301 redirect in .htaccess or in PHP [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 8 years ago.
Improve this question
Simple question:
I'm trying to maintain a list of 301 redirects for SEO reasons and I want to know if its better to be using .htaccess with redirect rules or should I maintain the list of redirects in PHP.
If you could explain why either one is better that would be great!
Keeping your redirects in .htaccess will be better for performance, as there will be no PHP interpreter initialization required for each redirection. On the other hand, you can do additional processing if you do it in PHP (stats counting, etc). If you want simple redirects and nothing else, place them in .htaccess just for the performance advantage.
For SEO purposes neither makes a difference as both results in the same thing; A Location change. Both are handled by the server and have the same impact on a Search Engine. So, based on that, go for whichever is the most efficient for you to handle.

Categories