URL GET request formatted as a deep link - php

I'm wondering how data passed to the URL can be "camouflaged" as a deep link. Here is an example of a site that does this: http://www.conradit.no/
I actually developed that site, but paths have been changed later.
So I have seen sites that does this even without referencing the index page (e.g. www.sometime.com/get/data/camouflaged)
I have seen some jQuery libraries that does this using anchor tags, but that is out of the question since users of the CMS I'm writing may want to use anchor tags on their pages.
I would like to know how this is done all server side using php and .htaccess files or such.
Thanks for all replies!

They use a rewrite engine, such as Apache's mod_rewrite.

The site is using some URL rewriting techniques. By the look of the URL path and the Server header field in the response I guess they’re using the so called path info (see Apache’s AcceptPathInfo) to have requests like /index.php/foo/bar redirected internally to /index.php with the path info /foo/bar.
But they could also use other techniques that can rewrite/redirect the requested URL based on patterns like Apache’s mod_rewrite.

Related

Is it possible to REWRITE a URL without htaccess file?

Is it possible to shorten a url without using htaccess file?
for example I have this url.
this/is/a/very/long/url.php
change to
short/url.php
I hope I can get good answer THX guys:)
yes, mostly used in frameworks
an approach called using a front controller
ex: your front controller is index.php
your page links are generated as a fashion of .../index.php/nything/url.php
but the actual link is .../this/is/long/url.php
the front controller extract the page information the client requested and show the relevant page related to it
read more : http://en.wikipedia.org/wiki/Front_Controller_pattern
This is a good question, there are multiple options however the .htaccess file is probably your best bet.
this SO post describes it
Handling the url rewriting serverside is key here since it will be much faster to execute and will not break your script when used on some URL's.
so www.yourdomain.com/test/4/twenty/long/url/could/be/shorter/
all the arguments after www.yourdomain.com, can be retrieved via various PHP methods, including reading up on PHP's $_SERVER would be a good idea, as lots of variables are placed in that global array.
mod_rewrite is part of Apache, so it needs to be configured in Apache config. .htaccess actually Apache "live" config "per directory".
In general the best way ( I think) to rewrite urls is to rewrite everything to one file, let's say index.php and then "redirect" to specific file basing on URL. You can read a lot about "URL routing" in PHP on the web.
You can use this code in Javascript for rewriting current URL:
if (location.href.indexOf("this/is/a/very/long/url.php") > -1)
location.assign(location.href.replace(/this\/is\/a\/very\/long\/(url\.php)/, "short/$1"));

A Dynamic website using PHP

I am a beginner PHP programmer. I searched google for a "Dynamic PHP website tutorials". I found some stuff. They use $_GET variable to make the website dynamic, so the URL's appear like this:
example.com/?page=home
example.com/?page=about
example.com/?page=Downloads
and so on...
But most of the dynamic websites that I found on the internet has links like this:
example.com
example.com/about
example.com/download and so on....
So how do they do so ?? Have they got folders for all the catogories ?? And Also some websites have article URLs (eg : example.com/articles/posts/2010/article1.php). It would be a reall mess if they've got folders for all items. If not then How ?? Can someone give an example please ?
If you're using apache then read: http://httpd.apache.org/docs/current/mod/mod_rewrite.html
If you're using IIS then read: http://www.iis.net/downloads/microsoft/url-rewrite
In order to use the $_GET variable, it must be in the query string (or being routed through some other means that isn't 'default').
For example, the URLs you're using would become.
example.com/?page=home
example.com/?page=about
example.com/?page=Downloads
Additionally, you can rewrite URLs using the .htaccess file (http://httpd.apache.org/docs/2.0/misc/rewriteguide.html)
You are interested in page routing.
htaccess and MVC routing may start you down the correct path :)
To echo everyone else, it's called a url rewite.
For example, the url
http://example.com/index.php?ext=blog&cat=news&date=12122012
can be rewritten as
http://example.com/blog/news/12-12-2012
This isn't automatic, it requires defining the patterns used for understanding the new URL in a file called .htaccess which usually resides in the servers root directory. Note that the preceding '.' in the filename makes it a hidden file.
When I was first getting used to PHP i found the site http://phpbuilder.com a great help. They have a lot of articles, and a forum that is fairly nice to noobies. http://devshed.com is a good site too, and has a large amount of information on subjects outside of PHP.
You can achieve that affect with folders, but most use rewrites (Apache). It's a bit too broad of a subject to go in to here, but if you just search for rewrite tutorials you'll find some pretty quickly.
The $_GET is only to get variables from the URL. While this can be used to make sites dynamic, this is a technique which is usually frowned upon.
With rewrites, you basically have a URL like /about, but the rewrite tells your server something like "act like this is actually ?page="about"), which you then use the $_GET to process.
Being PHP beginner I will not urge you to use .htaccess, As you will need to learn lot many things before you proceed further. You have 2 option to send a request one is GET and POST. You can get more information about same on internet.
Also you have an option to start your dynamic website using CMS and I will recommend you to use wordpress. CMS will have some in-built function which will help you to do your work faster. Also using their control panel you can update the URL format.
I will also urge you to go step by step and follow every tutorial that you will find on internet.
All the best
If you want to do this you have to use .htaccess file and have to load mod_rewrite in your apache server.
In you root directory create file named .htaccess
Then Write:
RewriteEngine On
RewriteRule ^(.*)\.php$ index.php?page=$1 [L,QSA]
And After that call a page
my-page.php
It will redirected as a index.php?page=my-page internally but in browser it will show as my-page.php

I want to use the strategy of wordpress for url rewriting

What is the strategy of wordpress for url rewriting.
In .htaccess they have only few line of code,for my app I need more than 80 line of code...
To 20 app's apache blows up and server too.
I have url structure like this:
http://localhost/list.php?title=two-wheel; (title var is used for search)
http://localhost/list.php?title=four-wheel&category=cars;
http://localhost/list.php?title=four-wheel&category=cars?features=car-alarm;
http://localhost/list.php?title=four-wheel&region=wyoming&category=cars?features=car-alarm;
and manny other pages.
How could I write my url's like them?
Can you provide an example of what code is need to write in .php page and in .htaccess based by wordpress strategy?
Wordpress loads any request into the application and then loads a map of regular expressions stored inside the database to resolve the actual command of the request.
This is done to support other types of URL rewriters - not only .htaccess but also PATHINFO and error pages.
Next to that plugins can add their own "rewrite-rules".
However this also has it's cons as it can consume a lot of resources and bring the script down.
If you want to rewrite URLs like them, feel free to use the sourcecode publicly available. However, I would suggest to review your rewrite rules first. Only because there are not so many rules within the .htaccess file, this does not mean that are no rules at all.

Dynamic mod_rewrite or how to plan a dynamic website

I'm trying to make a clean url for a blog on a dynamic website, but I think that the problem is that I don't know how to plan the website schema.
I read about how to use mod_rewrite and all I found is how to make "http://www.website.com/?category&date&post-title" to "http://www.website.com/category/date/post-title". that's works o.k for me.
The problem is that If my url looks like "http://www.website.com/blog/?id=34" this method won't work as far as I got it.
So, I have two questions:
1. Is there a way to use mod_rewrite (maybe read from a txt file) to read the post title of my blog and rewrite my url by date and post-title?
2. Should I rewrite my website to query the data from one index file in the homepage and use mod_rewrite to write the nice url? should I query also the date and the title of the post instead just the post ID?
mod_rewrite used to rewrite requests and it has nothing to do with urls. You have to change urls by hands.
yes, it's most common practice, to query the data from one index file
no, you can't use mod_rewrite to write the nice url
yes, an id must be present in the url along with title. your engine will just throw title away and use only id to retrieve an article.
Take a look at SO urls for an example
What you're talking about is commonly referred to as routing and lots of examples exist of different ways to do it with PHP. The most common approach uses the frontcontroller pattern, which means in the simple case rewriting all URLs to a single php file and then having that file determine what content to show dynamically based on the URL.
The most popular PHP frameworks (CakePHP, Symphony, Codeigniter, etc.) all have routing code in them which you might be able to use or might serve as inspiration. Alternatively this article covers lots of the basics if you want to do it yourself: http://www.phpaddiction.com/tags/axial/url-routing-with-php-part-one/
RewriteMap allows you to do all sorts of dynamic rewriting (text file, script, etc).

REALLY basic mod_rewrite question

I am trying to use SEO-friendly URLs for a website. The website displays information in hierarchical manner. For instance, if my website was about cars I would want the URL 'http://example.com/ford' to show all Ford models stored in my 'cars' table. Then the URL 'http://example.com/ford/explorer' would show all the Ford Explorer Models (V-6, V-8, Premium, etc).
Now for the question:
Is mod_rewrite used to rewrite a query string style URL into a semantic URL, or the other way around? In other words, when I use JavaScript to set window.location=$URL, should the URL be the query string version 'http://example.com/page.php?type=ford&model=explorer' OR do I internally use 'http://example.com/ford/explorer' which then gives me access to the query string variables?
Hopefully, someone can see my confusion with this issue. For what it's worth, I do have unique 'slugs' made for all my top level categories (obviously, the site isn't about cars).
Thanks for all the help so far. I got the rewrite working but it is affecting other paths on the site (CSS, JavaScript, images). I using the correct path structure for all these includes (ie '/images/car.png' and '/css/main.css'). Do I have to use an absolute path ('http://example.com/css/main.css') for all files? Thanks!
Generally, people who use mod_rewrite use the terminology like this:
I want mod_rewrite to rewrite A to be B.
What this means is that any request from the outside world for page A gets rewritten to file B on the server.
You want the outside world to see URLs that look like
A) http://example.com/ford/explorer
but your web server wants them to look like
B) http://example.com/page.php?type=ford&model=explorer
I would say you want to rewrite (A) to look like (B), or you want to rewrite the semantic URL into a query string URL.
Since all the links on your page are clicked on by the user and/or requested by the browser, you want them to look like (A). This includes links that javascript uses in window.location. They can and should look like (A).
once you have set up mod_rewrite then your links should point to the mod_rewritten version of the URL (in your example: http://mysite.com/ford/explorer). Internally in your system you will still reference the variables as if they are traditional query string name value pairs though.
Its also worth pointing out that Google is now starting to advocate more logical URLs from a search engine point of view, i.e. a query string over mod rewrite
Does that mean I should avoid
rewriting dynamic URLs at all? That's
our recommendation, unless your
rewrites are limited to removing
unnecessary parameters, or you are
very diligent in removing all
parameters that could cause problems.
If you transform your dynamic URL to
make it look static you should be
aware that we might not be able to
interpret the information correctly in
all cases
http://googlewebmastercentral.blogspot.com/2008/09/dynamic-urls-vs-static-urls.html
also worth looking at:
http://googlewebmastercentral.blogspot.com/2009/08/optimize-your-crawling-indexing.html

Categories