Page 1 of 1
mod_rewrite
Posted: Fri Jan 05, 2007 6:31 am
by malcolmboston
Ive just been reading up on HTaccess and im baffled tbh.
i have URL's that look like the following
Code: Select all
http://localhost/RedSquare/MainSite/cms/index.php?s=products&a=edit&productStockCode=71304
i would like it to look like
Code: Select all
http://localhost/RedSquare/MainSite/cms/index.php/products/edit/71304
How would i go about this?
Any help would be appreciated
Thanks, Mal
Posted: Fri Jan 05, 2007 6:38 am
by Chris Corbyn
You can do that with PHP itself. There's an argument separator directive in php.ini I think, and either way you can read it from $_SERVER["REQUEST_URI"].
With mod_rewrite it would be:
Code: Select all
RewriteBase /RedSquare/MainSite/cms/
RewriteRule ^index\.php/([A-Za-z0-9]+)/([a-zA-Z0-9]+)/([0-9]+)$ index.php?s=$1&a=$2&productStockCode=$3
Posted: Fri Jan 05, 2007 6:43 am
by malcolmboston
for whatever reason that doesnt work on the URL
Code: Select all
http://localhost/RedSquare/MainSite/cms/index.php?s=products&a=edit&productStockCode=71304
using
Code: Select all
RewriteEngine On
RewriteBase /RedSquare/MainSite/cms/
RewriteRule ^index\.php/([A-Za-z0-9]+)/([a-zA-Z0-9]+)/([0-9]+)$ index.php?s=$1&a=$2&productStockCode=$3
i woulod be very interested in hearing how it can be done with PHP (literally rewrite the URL from an end uer perspective, surely would reqwuire Javascript?)
Cheers
Posted: Fri Jan 05, 2007 7:17 am
by malcolmboston
i managed to build this using some simple str_replace
Code: Select all
urlrewrite Object
(
[originalAddress] => http://localhost/RedSquare/MainSite/cms/index.php?s=products&a=edit&productStockCode=70059
[NewAddress] => http://localhost/RedSquare/MainSite/cms/products/edit/70059
)
i cannot see anyway though i can transparently use this so that when a visitor goes to the NewAddress they are actually going to the OldAddress, isnt that what the rewrite engine does (in an overcomplicated way)
Posted: Fri Jan 05, 2007 10:30 am
by TheMoose
I think your problem is that you're still linking to
Code: Select all
http://localhost/RedSquare/MainSite/cms/index.php?s=products&a=edit&productStockCode=71304
and wanting it to show up as
Code: Select all
http://localhost/RedSquare/MainSite/cms/index.php/products/edit/71304
in the address bar. mod_rewrite and htaccess don't actually rewrite the URL that shows up in the address bar. What mod_rewrite is doing is secretly pointing anything that matches the clean look to instead point to the index.php file with the arguments.
If this is the case, change all your links in your site to point directly to
Code: Select all
http://localhost/RedSquare/MainSite/cms/index.php/products/edit/71304
add the htaccess lines that d11wtq posted, and put the htaccess file in the same directory as your index.php file. This will make it so that anytime you link directly to
Code: Select all
http://localhost/RedSquare/MainSite/cms/index.php/products/edit/71304
it gets pointed to
Code: Select all
http://localhost/RedSquare/MainSite/cms/index.php?s=products&a=edit&productStockCode=71304