473,322 Members | 1,778 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,322 software developers and data experts.

URL rewrite + htaccess

Hi there.
I have a domain, and i want every query string
redirected to index.php?
so domain.com/foo/bar would actually be domain.com/index.php?/foo/bar
Then i want to be able to say in index.php,
if QUERY_STRING == foo, do this etc.
(How) can i do this with htaccess?

thanks!

Jul 17 '05 #1
10 2112
frizzle wrote:
Hi there.
I have a domain, and i want every query string
redirected to index.php?
so domain.com/foo/bar would actually be domain.com/index.php?/foo/bar
Then i want to be able to say in index.php,
if QUERY_STRING == foo, do this etc.
(How) can i do this with htaccess?

thanks!


RewriteEngine On
RewriteRule ^(.*)$ index.php?$1

If you want:
example.com/foo/bar/?id=10 to work:

RewriteRule ^(.*)$ index.php?$1 [QSA]

Then in index.php, your _GET array should (in theory, not tested) look like:

array(
'/foo/bar/' => '',
'id' => 10
)

$_SERVER['QUERY_STRING'] should be:
?/foo/bar/&id=10

Don't know how well

--
Justin Koivisto - ju****@koivi.com
http://koivi.com
Jul 17 '05 #2
frizzle wrote:
Hi there.
I have a domain, and i want every query string
redirected to index.php?
so domain.com/foo/bar would actually be domain.com/index.php?/foo/bar
Then i want to be able to say in index.php,
if QUERY_STRING == foo, do this etc.
(How) can i do this with htaccess?

thanks!


RewriteEngine On
RewriteRule ^(.*)$ index.php?$1

If you want:
example.com/foo/bar/?id=10 to work:

RewriteRule ^(.*)$ index.php?$1 [QSA]

Then in index.php, your _GET array should (in theory, not tested) look like:

array(
'/foo/bar/' => '',
'id' => 10
)

$_SERVER['QUERY_STRING'] should be:
?/foo/bar/&id=10

Don't know how well

--
Justin Koivisto - ju****@koivi.com
http://koivi.com
Jul 17 '05 #3
Wow, thanks!
Just what i needed!

Jul 17 '05 #4
Wow, thanks!
Just what i needed!

Jul 17 '05 #5
I'm sorry,
i cheered to early...

Without '[QSA]':
'domain.com' gives a 400 error.
'domain.com?foo' gives a 400 error.
'domain.com/' gives 'index.php'
'domain.com/foo' gives 'index.php'

With '[ QSA]'
'domain.com' gives a 400 error.
'domain.com?foo' gives a 400 error.
'domain.com/' gives 'index.php'
'domain.com/foo' gives 'index.php&foo' (should'nt that be
'index.php?foo' ?)
'domain.com/?foo' gives 'index.php&&foo' (should'nt that be
'index.php?&foo' ?)

Thanks in advance.

Jul 17 '05 #6
I'm sorry,
i cheered to early...

Without '[QSA]':
'domain.com' gives a 400 error.
'domain.com?foo' gives a 400 error.
'domain.com/' gives 'index.php'
'domain.com/foo' gives 'index.php'

With '[ QSA]'
'domain.com' gives a 400 error.
'domain.com?foo' gives a 400 error.
'domain.com/' gives 'index.php'
'domain.com/foo' gives 'index.php&foo' (should'nt that be
'index.php?foo' ?)
'domain.com/?foo' gives 'index.php&&foo' (should'nt that be
'index.php?&foo' ?)

Thanks in advance.

Jul 17 '05 #7
* bump *
Please.. ?

Jul 17 '05 #8
frizzle wrote:
I'm sorry,
i cheered to early...

Without '[QSA]':
'domain.com' gives a 400 error.
'domain.com?foo' gives a 400 error.
'domain.com/' gives 'index.php'
'domain.com/foo' gives 'index.php'

With '[ QSA]'
'domain.com' gives a 400 error.
'domain.com?foo' gives a 400 error.
'domain.com/' gives 'index.php'
'domain.com/foo' gives 'index.php&foo' (should'nt that be
'index.php?foo' ?)
'domain.com/?foo' gives 'index.php&&foo' (should'nt that be
'index.php?&foo' ?)

Thanks in advance.


Dunno... Try in alt.apache.configuration group, or try changing your method.

For instance, this is similar to what I use:

RewriteRule ^([^/]+)(/([^/]+))?(/([^/]+))?(/([^/]+))?/?$
x.php?v1=$1&v2=$3&v3=$5&v4=$7 [L,NS,QSA]

--
Justin Koivisto - ju****@koivi.com
http://koivi.com
Jul 17 '05 #9
I'm sure you're no idiot, but just a heads up incase you are unaware of
this. Be careful about any secure areas of your site to which you want
restricted access, for example PHP include folders or anything. I have
seen a few sites which use this "index.php gateway" approach, where
simply changing the string passed to the script allows access to
anything, sometimes even sending PHP source unparsed. This problem may
or may not affect you, depending on how you've done things.

Adam
Jul 17 '05 #10
First of all, thanks for your warning!

Though i haven't got a solution yet for my initial posted problem
i use sort of the following method:

$string = $_SERVER['QUERY_STRING'];

$allowed_strings = array('home', 'contact', 'etc');

if(!in_array($string, $allowed_strings))
{

$string = 'home';

};

I thought this was quite safe, but please do inform me if not!

Thanks!

Frizzle.

Jul 17 '05 #11

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: frizzle | last post by:
Hi group, I know this isn't the right group, but i didn't know what group else it should be. I have a php/mySQL system, wich uses mod rewrite to enhance urls. I have the following...
2
by: musiq021 | last post by:
I need a rewrite rule/rules for an .htaccess file that does the following... if a second variable is supplied... rewrites this... artistcat_VAR1_VAR2.htm --> artists.php?cat=VAR1&page=VAR2 if only...
5
by: Lupus | last post by:
Hello everybody In apache I used a feature called a "Rewrite rule" inside a .htaccess file to process the URL : i.e. http://www/mypage.html =http://www/page.php?page=mypage Now I'd like to do...
1
by: kinklade | last post by:
Hi, I have been attempting to find a solution to a problem I have been having with what should be fairly strightforward. In my .htaccess I wish to put a rewriterule to replace /?page=york with...
1
by: phpmind | last post by:
I am doing a mod rewrite on a page like the following: www.mysite.com/user/jsmith/ executes the following: www.mysite.com/result.php?user=jsmith This works but the top of my page where my...
3
by: Joe | last post by:
Hello, I currently have a file system where images and assets are stored in a directory like this: http://www.domain.com/assets/media/CLIENT_NAME/uploads/CLIENT_DIR/CLIENT_FILES Which holds...
1
by: arunj82 | last post by:
Hi all, I have a doubt in redirecting a url in htaccess file. for example, http://example.com/subfolder1/subfolder2 to http://www.example.com/subfolder1/subfolder2 How can do that...
0
by: adamjblakey | last post by:
Hi, I am working off local host and i want to use htaccess but i am unsure on the code that i would need. This is my normal re-write rule for a domain like e.g http://www.bob.com/info..php ...
8
hsriat
by: hsriat | last post by:
I had a .htaccess file for Rewrite on my server and was working fine. Now when I used the same code in 1and1 hosting, its not working. May be something is wrong or unexpectedly good happening...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.