Page 1 of 1

echo $this->Question("htaccess")

Posted: Fri Oct 31, 2003 7:36 am
by Gen-ik
It's probably been asked before ( yes I've searched ) but I'm stumped on something.

If I want to send a variable to the index.php page of my website (from the index.php page) using a method like "Bobs/bits" how can it be done?

In 'real world' terms the actual url would be index.php?Bobs=bits

So, from the site (and when shown in the address bar) a url might look like this.... <a href="Bobs/bits">link</a> but in actual fact it's telling the server to link to index.php?Bobs=bits


Hope that's not too confusing. I know it can be done using htaccess but I'm not sure of the syntax or where to put the .htaccess file.


Any help would be mucho good.

Posted: Fri Oct 31, 2003 7:58 am
by RTT
I had to read it twice, but I get what you mean now. I use this method on every website I make, it looks so much better, and is search engine friendly :)

.htaccess:

Code: Select all

<Files bobs>
    Forcetype application/x-httpd-php
</Files>
Then experiment with explode()ing $_SERVER['REQUEST_URI'] :)

Posted: Fri Oct 31, 2003 9:36 am
by volka
also take a look at http://httpd.apache.org/docs-2.0/mod/mo ... ewriterule (... if it is an apache server)
If you set up a rewrite-rule within .htacess (or a <directory> section) remember that the url you have to handle is relative to the position of the rewrite rule, e.g. if your .htaccess is in <documentroot>/myscripts/php and want to catch http://my.serv.er/myscripts/php/bobs/bits you must not install a rule for myscripts/php/(.+)/(.+)$ but (.+)/(.+)$

Posted: Fri Oct 31, 2003 11:27 am
by Gen-ik
Ok cheers guys I'll play around with your ideas :)

Posted: Fri Oct 31, 2003 12:26 pm
by volka
ah, and something that's sometimes forgotten when trying to set up a rewrite rule
Syntax: RewriteRule Pattern Substitution
Context: server config, virtual host, directory, .htaccess
Override: FileInfo
"Override: FileInfo"! You must be allowed to do so ;-)

Posted: Fri Oct 31, 2003 12:48 pm
by phice
http://www.phpfreaks.com/tutorials/23/0.php - It got me started with what I wanted, hopefully you'll have the same luck as me.

Posted: Fri Oct 31, 2003 3:01 pm
by Gen-ik
Noooooooo.... so close yet so very far away :cry:

Ok. Things are sort of working now but I keep running into one of two problems depending on what tweaks I do to the .htaccess file. Sometimes I get a a blank page with nothing on it, sometimes I get the correct page showing up but none of the images load up correctly.... I'm guessing this is because the page thinks it's somewhere it's not.


Let's go through it.

The path to the website directory is,
c:/apache/websites/htdocs/urban-republic/

The index page is obviously in the urban-republic folder,
c:/apache/websites/htdocs/urban-republic/index.php

The image folder is also in the urban-republic folder,
c:/apache/websites/htdocs/urban-republic/img/


The mod_rewrite I'm trying to get working is,
Query String URL : some/thing.mod
mod_rewrite URL : index.php?some=thing


The .htaccess file contains,
RewriteEngine On
RewriteRule ^(.*)/(.*).mod /urban-republic/index.php?$1=$2



Help! Please! Once I get to grips with it I should be fine :wink:

Posted: Fri Oct 31, 2003 3:17 pm
by volka
probably <img src="../img/whatsoever.gif">
The browser (not aware of being served by /urban-republic/index.php) concatenates this to /urban-republic/some/../img/whatsoever.gif => /urban-republic/img/whatsoever.gif

Posted: Fri Oct 31, 2003 4:40 pm
by Gen-ik
Thanks volka it's now working fine. All I need to do now is convince my host to allow "Override: FileInfo" which might be a bit more tricky.

At least I know how to do RewriteRule thing now :D

Posted: Fri Oct 31, 2003 5:57 pm
by Gen-ik
Erm, sorry... just one more thing.

This is the RewriteRule I'm currently using,

^(.*)/(.*).mod /rewrite/$1.php?run=$2

It keeps saying it can't find the page, but if I replace the $1 with news it works fine... I'm guessing I need to escape something somewhere?

It should work like this,
news/editor.mod -> news.php?run=editor
or
mail/view.mod -> mail.php?run=view


Thanks again, you've all been a massive help.

Posted: Fri Oct 31, 2003 7:43 pm
by Gen-ik
STOP PRESS!

I think I've sorted it out and things are working ok (fingers crossed).
I know it's nothing special but this is what I'm using now...

Code: Select all

RewriteEngine On

# Check for a .mod extension
# --------------------------
  RewriteCond %&#123;REQUEST_URI&#125; \.mod$
  RewriteRule ^(.*)/(.*).mod /rewrite/$1?mod=$2 &#1111;L]

# Normal link execution if URI doesn't contain .exe
# --------------------------------------------------------
  RewriteRule (%&#123;REQUEST_URI&#125;) $1
...... and on another note my Web Host is fantastic, they've done their thing and I can now use Rewrite on-line, and it was done within 20 minutes.


I'm happy :D

Posted: Fri Oct 31, 2003 10:44 pm
by volka
;-)