[Last Call] Learn about multicloud storage options and how to improve your company's cloud strategy. Register Now

x
?
Solved

Base URI and Pretty Links

Posted on 2011-02-16
3
Medium Priority
?
377 Views
Last Modified: 2012-06-27
I am working on some PHP scripts which are to work on various different web servers. At the moment the scripts work with urls like the following:

http://example.com/something/special?a=1&b=2&c=3

I need to make it possible to switch from the above format, to the below format for servers where the above is either not possible or more complicated to configure (for end-user):

http://example.com/index.php?route=something/special&a=1&b=2&c=3

All URIs utilise a global variable which presents the start of the entire address:
define('HTTP_BASE_URI', 'http://example.com/');

Open in new window

But obviously the following equivalent will also be required:
define('HTTP_BASE_URI', 'http://example.com/index.php?route=');

Open in new window


The base URI is used as follows to produce the first URI, but the second scenario renders an invalid URI because it contains two ? symbols:
echo HTTP_BASE_URI . 'something/special?a=1&b=2&c=3';

Open in new window


Bad Output:
http://example.com/index.php?route=something/special?a=1&b=2&c=3

This is quite a big system which contains a lot of similar (but different) scenarios. What is the best solution (one that does not rely on .htaccess) to resolve this? Ideally one which doesn't incur too many changes upon the system...
0
Comment
Question by:numberkruncher
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 13

Author Comment

by:numberkruncher
ID: 34910677
One interesting point is that the bad URI resolves to the following PHP $_GET array:
array(
   'route' => 'something/special?a=1'
   'b' => '2',
   'c' => '3'
)

Open in new window

Obviously I can fix this by doing something like the following (with better error checking obviously):
$temp = explode('?', $_GET['route']);
$_GET['route'] = $temp[0];

$temp = explode('=', $temp[1]);
$_GET[$temp[0]] = $temp[1];

Open in new window


But will this cause problems? Especially with SEO?
0
 
LVL 20

Accepted Solution

by:
thehagman earned 2000 total points
ID: 34911470
Why not use
echo myURI('/something/special','a=1&b=2&c=3')

Open in new window

and either define
myURI($path,$params) { return 'http://example.com' . $path . ($params? '?'.$params : '')

Open in new window

or
myURI($path,$params) { return 'http://example.com/index.php?route=' . $path . ($params? '&'.$params : '')

Open in new window

0
 
LVL 13

Author Closing Comment

by:numberkruncher
ID: 34912005
Thanks, that should do the trick.
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

When it comes to write a Context Sensitive Help (an online help that is obtained from a specific point in state of software to provide help with that state) ,  first we need to make the file that contains all topics, which are given exclusive IDs. …
This article explains how to prepare an HTML email signature template file containing dynamic placeholders for users' Azure AD data. Furthermore, it explains how to use this file to remotely set up a department-wide email signature policy in Office …
In this tutorial viewers will learn how to embed videos in a webpage using HTML5. Ensure your DOCTYPE declaration is set to HTML5: "<!DOCTYPE html>": Use the <video> tag to insert a video. Define the src as the URL of your video; this is similar to …
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …
Suggested Courses

650 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question