Rewrite & PHP variables

Discuss practical ways rearrange URLs using mod_rewrite.

Postby jackfeliciano » Mon Jul 22, 2002 9:54 pm

Do you agree these rules are going to do what I want them to?

RewriteEngine on
RewriteCond %{REQUEST_URI} ^/([a-z0-9]*)$
RewriteRule ^(.*) index.php?variable=$1

(I want to transform URLs such as: "http://www.mysite.com/test" into "http://www.mysite.com/index.php?variable=test")

Heeeeelp!

Thank you, folks!


Jack.
jackfeliciano
 
Posts: 1
Joined: Thu Jul 18, 2002 4:00 pm

Postby Brett » Mon Aug 05, 2002 12:04 pm

Yep, on my server that works exactly as you stated.
Brett
 
Posts: 82
Joined: Tue Jul 10, 2001 4:00 pm
Location: yohost.com

Postby webgraph » Tue Sep 10, 2002 1:48 pm

Will this method also work for a directory one level down? For instance, instead of:

http://www.mysite.com/test

I want to be able to also do:

http://www.mysite.com/test/site

and have it rewrite to:

http://www.mysite.com/test/index.php?page=site

Thanks for any help!
webgraph
 
Posts: 2
Joined: Tue Sep 10, 2002 1:43 pm

Postby Guest » Mon Oct 28, 2002 2:11 am

Try...
Code: Select all
RewriteRule ^(/[a-z0-9]+)*/([a-z0-9]+) /index.php?variable=$2
Guest
 

Same Problem

Postby marting » Wed Jan 21, 2004 11:40 pm

Hi !

I also want to rewrite:
Code: Select all
http://www.domain.com/$news/
and http://www.domain.com/$news/$user/

to
Code: Select all
http://www.domain.com/index.php?site=$news&user=$user


My Apache 1.3.27 is running on Win2k !
The mod_rewrite is loaded BUT i am not able to do a RewriteLog or to set a LogLevel !!!
I always get an error in apache-error.log "is not allowed here" !

With this code in .htaccess (in root of htdocs):
Code: Select all
RewriteRule ^(/[a-z0-9]+)*/([a-z0-9]+) /index.php?variable=$2

i get a "404 Not found" when accessing /news/ in browser (the directory does really not exist -> it should be used VIRTUAL) !

What am i doing wrong !?
marting
 
Posts: 1
Joined: Wed Jan 21, 2004 11:27 pm

Postby Guest » Thu Feb 26, 2004 10:38 pm

I would like to do something similar. I have my site set up to detect a finite list of mobile browsers and serve up a mobile-friendly version of the site. However, there is no way I can enumerate ALL possible mobile browsers so I want to have the option to just let them go to the /mobile directory. Then mod_rewrite to the root directory but with a variable set.

I can force the mobile theme one of two ways: either add "&mobile=1" to all URL's or better yet I would rather force the $HTTP_USER_AGENT variable to a known mobile browser, like "WebPro".

First, is it possible to modify that user agent variable using mod_rewrite? If not, then setting "mobile=1" would be OK, but I don't prefer that as my stats by page (and possibly the search engine stats) would be off.



But I also need every request to modules.php to go to the appropriate place. eg:
http://www.palmzone.net/mobile/modules. ... ns&artid=2

to go to:
http://www.palmzone.net/modules.php?nam ... 2&mobile=1


Another important thing I don't understand is how subsequent clicks on URL's from the redirected page (no /mobile) will still retain the /mobile directory so that subsequent mod_rewrites continue to add the "&mobile=1".

This is what I'm thinking anyway, but it may be too complex and someone has a better idea...

TIA!
Guest
 


Return to Friendly URLs with Mod_Rewrite

Who is online

Users browsing this forum: Google [Bot] and 21 guests

cron