question title in url like stackoverflow - .htaccess

Id like to make a url similar to stackoverflow where the user can type in a textbox and then on refresh a url is created. like the url to this question uses the title i typed in. id like to make that effect on my own site. thanks. I think this may have to incorporate a .htaccess file??

You may notice that the words from the title in the question URL don't affect where the URL goes. The following link goes to the same place: https://stackoverflow.com/questions/6366169/foo-bar-baz
All you need to do is make your server process respond to the URL in the correct way. How you do this will depend on your chosen server architecture and/or programming language. Using .htaccess is unrelated.

maybe this link will help you understand how you can achieve your goal https://docs.djangoproject.com/en/dev/topics/http/urls/ (django)
http://www.phpaddiction.com/tags/axial/url-routing-with-php-part-one/ (php)
other web frameworks operate in similar way
in the given example you can interpret the url http://stackoverflow.com/posts/9701416/edit like this:
if you find "posts" in the url the next part of the url (9701416) is a parameter and the last part is the action so your main controller will load a post with id 9701416 and it will be loaded in edit mode (it doesn't mean there's a sub directory questions with sub directory 6366169 with a file "post")

Related

How to detect change in the URL - Dart/Flutter

I'm trying to fetch a specific part from the youtube URL. For example:- if the user has put the following URL https://www.youtube.com/watch?v=KOjE7cQ0FkA
I would fetch the following part KOjE7cQ0FkA using the below method
String url = urlController.text; // https://www.youtube.com/watch?v=KOjE7cQ0FkA
List urlList = url.split("=");
String urlCode = await urlList[1];
but sometimes people copy the video link from mobile and this is how it would appear
https://youtu.be/KOjE7cQ0FkA In such case, above code wouldn't work
So how can I detect which URL is put by the user and perform a split operation accordingly
Sorry, if my question sounds stupid but I hope you got an idea that what I'm trying to achieve here
There are many ways to approach this. One way would be to parse the URL (have a look at this SO question).
With this approach you could check if the query parameter watch is present -- if not the URL is probably in the mobile format.
Another approach would be to define a regex expression for the Video-ID (KOjE7cQ0FkA) part of the URL. That way you can extract the Video-ID regardless of the format of the URL. I would probably go with that approach.
Your regex could look like this: ([a-zA-Z]+(\d[a-zA-Z]+)+)
I used this site to create the regex. You probably need to modify it a little bit. Also if the ID has a fixed length that is a great criteria to filter by.

How do I go about changing the contents of a page based on the URL? Express.js, Node.js

Okay. I know this question was a bit confusing, so let me decompose my question a bit further. For example, let's say I have the URL: https://example.com. I have an open GET endpoint at: https://example.com/user/* that will return a specific user's information based on what the contents of the "*" is. Lets say a specific user is at: https://example.com/user/12345. On an HTML page, I would like to put that user's profile contents and some of their hobbies. Again, this is theoretical. I have explored various solutions such as Handlebars.js which can dynamically change values based on the server request. However, this solution does not always work. Take a search engine for example at: https://mysearchengine.com/search?query=dogs. Here, we have a search query for dogs. How do I render all of the results to a HTML document without using a dynamic content module like Handlebars?
This question was particularly difficult to ask, so please do not mark this as "not enough information". I would be more than happy to clarify any questions you may have about the nature of my query. Thank you so much in advance,
Flight Dude.
Just wanted to let y'all know I found my answer: EJS. Thanks!

Web - Redirect website url that is being used by a request

I know that the title isn't very clear, but my problem is kind of complicated.
Lets say I am on this website (lets say, example.com), and the website is taking images from another website ( images.com ).
I want to change something so that instead of images.com, example.com takes images from myimages.com.
Still too complicated? I will break it down more. This is what currently is hapenning:
example.com takes images from images.com (I dont know what request it uses)
This is want I want:
example.com takes images from myimages.com
If you still dont understand, please comment below!
If example.com is database driven, simply download the database and do a find for "images.com" and replace with "myimages.com", then reupload the database.
If it is static HTML, repeat by downloading the HTML from example.com, using something like Notepad++ to find in files, then replace all in exactly the same way.
As a sidenote, you should provide as much information as possible as to which platform, codebase and type of request you mean. It will generate higher quality answers.
Most of the time this is done through a GET rest call if done on the server side see https://www.tutorialspoint.com/restful/.
If it is done client side(html css javascript) code you will need to find where that reference is defined in the code and change it. In HTML image tags have an src attribute that tells the page where to grab the image from.
If you go to the example shown here: https://www.w3schools.com/tags/tag_img.asp
and change the image tag src like I do below attribute and click run it will show a the stack overflow image located at https://i.stack.imgur.com/oURrw.png.
<img src="https://i.stack.imgur.com/oURrw.png" alt="Smiley face"
height="42">

Friendly URLs when using a Record ID for dynamic content

I've read a bit on the matter of friendly urls and I'm a little unsure as to what is better.
I currently have my website using a structure of http://www.domain.com/page.php?id=2
I am using the record id to determine the content of the page. My record id's are numeric and increment for new pages added. The content of existing pages can change completely over time. But, still use the same record id (this is a cms so the client may do this).
The way I understand it I have two options for friendly urls:
http://www.domain.com/page/2
http://www.domain.com/some-text-describing-the-page
Now because I identify the content by the record id, I would assume the first option would make more sense.
My client seems to want option two.
After some reading I found two conflicting points.
As per Tim Berners-Lee (the architect of the WWW) he states that you want a URI which will have the potential to remain the same 2 months, 2 years, 200 years from now. So you DO NOT want to use a page title or something similar for your pages. If you change your pages content you are either forced to change the content and leave the URI alone, or change the URI and are stuck with dangling links. You can read his article here (http://www.w3.org/Provider/Style/URI)
However, a number of other people on the internet (with no know authority to me) clearly state that you need to have a descriptive yet short URI for the best SEO value. From what I read, mostly for the purpose of backlinks and having keywords in the anchor text since people just use the link itself for the anchor text. So having keywords in the link itself helps search engines know what the link is about without a custom title.
It seems to me the difference has to do with long term VS short term.
Am I grasping this correctly?
If I am to use a slug style URI as defined by the user, do I have to just allow my user to type in whatever they want to a field and check against the current database to see if it exist? If so, am I supposed to anticipate static links by running a query for the know record id and then use the result to generate the url which would just be rewritten back to the format: http://www.domain.com/page.php?id=2?
It seems to me that would be a lot of extra overhead.
I would suggest something in the middle of those two:
http://www.domain.com/page/2/some-text-describing-the-page
or without page:
http://www.domain.com/2/some-text-describing-the-page
You can still get page Id from the Url, and there is a title as well! And what even more important, you're still able to get correct content, even when page title change later.
So think about situation like that: User creates a page, it receives Id=4 and it's title is My great title. From that information Url is generated, and is e.g. http://www.domain.com/page/3/my-great-title. After 2 months user changes the title to This title is better then the last one!. Url changes as well to http://www.domain.com/page/3/this-title-is-better-then-the-last-one. However, there is still 3 within the Url, so you're able to show right content! You can also check, if the rest of Url is actual, and redirect (301 would be the best one) to new one to let search engines know, that Url changed.

SEO optimized search results without JavaScript

I haven't found a direct answer for my question, so here it is:
I am trying to get my search results to be user and seo friendly. I believe it is a good idea to get rid of a couple of elements:
POST search should be avoided so the browser does not bug a user to
re-submmit the form if he goes back.
The question mark that appends the query string
The input name that goes with the form submmit if it is processed via an http GET (like ?search_input=cellphones)
So my question is a bit more: how do I turn a form submit into something like:
...mywebsite.com/search/my-search-term
...without using JavaScript to cause a redirect, but instead the form itself?
Do you guys tweak with .htaccess redirects to make your urls more "clickable", or just leave it be with the query string?
Just to be clear, the purpose of having the search user-optimized is clearly for people generating traffic through link distribution, and not to be indexed in a way or another by se's.
Thanks in advance!

Resources