echo $this->Question("htaccess")
Moderator: General Moderators
echo $this->Question("htaccess")
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.
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.
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:
Then experiment with explode()ing $_SERVER['REQUEST_URI'] 
.htaccess:
Code: Select all
<Files bobs>
Forcetype application/x-httpd-php
</Files>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 (.+)/(.+)$
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 (.+)/(.+)$
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.
Noooooooo.... so close yet so very far away
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
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
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.
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.
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...
...... 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
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 %{REQUEST_URI} \.mod$
RewriteRule ^(.*)/(.*).mod /rewrite/$1?mod=$2 їL]
# Normal link execution if URI doesn't contain .exe
# --------------------------------------------------------
RewriteRule (%{REQUEST_URI}) $1I'm happy
