Welcome to MobyThreads.com!
FAQFAQ      ProfileProfile    Private MessagesPrivate Messages   Log inLog in
All support for the MobyThreads Threaded phpBB MOD can now be found on welsolutions at this forum

mod_rewrite help

 
   Web Hosting and Web Master Forums (Home) -> Webmaster RSS
Next:  What is the worst College Web Site you have seen?  
Author Message
Karl Groves

External


Since: May 30, 2006
Posts: 452



(Msg. 1) Posted: Mon Aug 14, 2006 12:30 pm
Post subject: mod_rewrite help
Archived from groups: alt>www>webmaster (more info?)

I would like to change:
www.example.com?id=foo

to simply:
www.example/foo

All I seem to be able to work out is
www.example/id/foo which I don't want.

TIA

--
Karl Groves
www.karlcore.com

 >> Stay informed about: mod_rewrite help 
Back to top
Login to vote
Karl Groves

External


Since: May 30, 2006
Posts: 452



(Msg. 2) Posted: Mon Aug 14, 2006 1:26 pm
Post subject: Re: mod_rewrite help [Login to view extended thread Info.]
Archived from groups: per prev. post (more info?)

GreyWyvern <spam.DeleteThis@greywyvern.com> wrote in
news:op.teacffqrsl6xfd@news.nas.net:

> And lo, Karl Groves didst speak in alt.www.webmaster:
>
>> I would like to change:
>> www.example.com?id=foo
>>
>> to simply:
>> www.example/foo
>>
>> All I seem to be able to work out is
>> www.example/id/foo which I don't want.
>
> Surely[1] you mean you'd like to map:
> www.example.com/?id=foo
>
> to:
> www.example.com/foo
>
>
> Correct? If so try:
>
>
> RewriteEngine On
>
> RewriteCond %{QUERY_STRING} ^id=(.*)$
> RewriteRule ^$ /%1? [R=301]
>
>

Didna work. Got a 404


>
> [1] Begging your pardon for calling you Shirley.
>

I've been called worse


--
Karl Groves
www.karlcore.com

 >> Stay informed about: mod_rewrite help 
Back to top
Login to vote
Karl Groves

External


Since: May 30, 2006
Posts: 452



(Msg. 3) Posted: Mon Aug 14, 2006 1:32 pm
Post subject: Re: mod_rewrite help [Login to view extended thread Info.]
Archived from groups: per prev. post (more info?)

GreyWyvern <spam.DeleteThis@greywyvern.com> wrote in
news:op.teadrzj9sl6xfd@news.nas.net:

> And lo, Karl Groves didst speak in alt.www.webmaster:
>
>> GreyWyvern <spam.DeleteThis@greywyvern.com> wrote:
>>
>>> www.example.com/?id=foo
>>> to:
>>> www.example.com/foo
>>>
>>> RewriteEngine On
>>>
>>> RewriteCond %{QUERY_STRING} ^id=(.*)$
>>> RewriteRule ^$ /%1? [R=301]
>>
>> Didna work. Got a 404
>
> I tested it on my own server before posting it here, and it WFM. Do
> you get a 404 when you go to www.example.com/foo directly?


Yeah.
What's weird is now, if I go to www.example.com/?id=foo it redirects me to
www.example.com/foo







--
Karl Groves
www.karlcore.com
 >> Stay informed about: mod_rewrite help 
Back to top
Login to vote
Karl Groves

External


Since: May 30, 2006
Posts: 452



(Msg. 4) Posted: Mon Aug 14, 2006 1:45 pm
Post subject: Re: mod_rewrite help [Login to view extended thread Info.]
Archived from groups: per prev. post (more info?)

GreyWyvern <spam.DeleteThis@greywyvern.com> wrote in
news:op.tead4rqcsl6xfd@news.nas.net:

> And lo, Karl Groves didst speak in alt.www.webmaster:
>
>> GreyWyvern <spam.DeleteThis@greywyvern.com> wrote:
>>
>>> And lo, Karl Groves didst speak in alt.www.webmaster:
>>>
>>>> GreyWyvern <spam.DeleteThis@greywyvern.com> wrote:
>>>>
>>>>> www.example.com/?id=foo
>>>>> to:
>>>>> www.example.com/foo
>>>>>
>>>>> RewriteEngine On
>>>>>
>>>>> RewriteCond %{QUERY_STRING} ^id=(.*)$
>>>>> RewriteRule ^$ /%1? [R=301]
>>>>
>>>> Didna work. Got a 404
>>>
>>> I tested it on my own server before posting it here, and it WFM. Do
>>> you get a 404 when you go to www.example.com/foo directly?
>>
>> Yeah.
>> What's weird is now, if I go to www.example.com/?id=foo it redirect
> s me
>> to
>> www.example.com/foo
>
> I'm confused then, because I thought that's what you wanted.
>

Well, now the PHP script isn't liking the lack of the ID in the URL.



--
Karl Groves
www.karlcore.com
 >> Stay informed about: mod_rewrite help 
Back to top
Login to vote
spam19

External


Since: May 08, 2004
Posts: 952



(Msg. 5) Posted: Mon Aug 14, 2006 2:03 pm
Post subject: Re: mod_rewrite help [Login to view extended thread Info.]
Archived from groups: per prev. post (more info?)

And lo, Karl Groves didst speak in alt.www.webmaster:

> I would like to change:
> www.example.com?id=foo
>
> to simply:
> www.example/foo
>
> All I seem to be able to work out is
> www.example/id/foo which I don't want.

Surely[1] you mean you'd like to map:
www.example.com/?id=foo

to:
www.example.com/foo


Correct? If so try:


RewriteEngine On

RewriteCond %{QUERY_STRING} ^id=(.*)$
RewriteRule ^$ /%1? [R=301]


Grey

[1] Begging your pardon for calling you Shirley.

--
The technical axiom that nothing is impossible sinisterly implies the
pitfall corollary that nothing is ridiculous.
- http://www.greywyvern.com/orca#search - Orca Search: Full-featured
spider and site-search engine
 >> Stay informed about: mod_rewrite help 
Back to top
Login to vote
Karl Groves

External


Since: May 30, 2006
Posts: 452



(Msg. 6) Posted: Mon Aug 14, 2006 2:22 pm
Post subject: Re: mod_rewrite help [Login to view extended thread Info.]
Archived from groups: per prev. post (more info?)

GreyWyvern <spam RemoveThis @greywyvern.com> wrote in
news:op.teafmfnqsl6xfd@news.nas.net:

> And lo, Karl Groves didst speak in alt.www.webmaster:
>> GreyWyvern <spam RemoveThis @greywyvern.com> wrote:
>>> And lo, Karl Groves didst speak in alt.www.webmaster:
>>>> GreyWyvern <spam RemoveThis @greywyvern.com> wrote:
>>>>> And lo, Karl Groves didst speak in alt.www.webmaster:
>>>>>> GreyWyvern <spam RemoveThis @greywyvern.com> wrote:
>>>>>>
>>>>>>> www.example.com/?id=foo
>>>>>>> to:
>>>>>>> www.example.com/foo
>>>>>>>
>>>>>>> RewriteEngine On
>>>>>>>
>>>>>>> RewriteCond %{QUERY_STRING} ^id=(.*)$
>>>>>>> RewriteRule ^$ /%1? [R=301]
>>>>>>
>>>>>> Didna work. Got a 404
>>>>>
>>>>> I tested it on my own server before posting it here, and it WFM.
>>>>> D
> o
>>>>> you get a 404 when you go to www.example.com/foo directly?
>>>>
>>>> Yeah.
>>>> What's weird is now, if I go to www.example.com/?id=foo it redire
> ct
>>> s me
>>>> to
>>>> www.example.com/foo
>>>
>>> I'm confused then, because I thought that's what you wanted.
>>
>> Well, now the PHP script isn't liking the lack of the ID in the URL.
>
> You mean the PHP script is still looking for the id in the query
> string? Perhaps we have things backwards then and really you wish to
> *rewrite* www.example.com/foo to www.example.com/?id=foo
>
> In that case, we'd do:
>
> RewriteEngine On
>
> RewriteRule ^([^/]+)$ /?id=$1 [L]
>
>


Now www.example.com/foo gives an HTTP 500 error



--
Karl Groves
www.karlcore.com
 >> Stay informed about: mod_rewrite help 
Back to top
Login to vote
spam19

External


Since: May 08, 2004
Posts: 952



(Msg. 7) Posted: Mon Aug 14, 2006 2:32 pm
Post subject: Re: mod_rewrite help [Login to view extended thread Info.]
Archived from groups: per prev. post (more info?)

And lo, Karl Groves didst speak in alt.www.webmaster:

> GreyWyvern <spam.DeleteThis@greywyvern.com> wrote:
>
>> www.example.com/?id=foo
>> to:
>> www.example.com/foo
>>
>> RewriteEngine On
>>
>> RewriteCond %{QUERY_STRING} ^id=(.*)$
>> RewriteRule ^$ /%1? [R=301]
>
> Didna work. Got a 404

I tested it on my own server before posting it here, and it WFM. Do you
get a 404 when you go to www.example.com/foo directly?

>> [1] Begging your pardon for calling you Shirley.
>
> I've been called worse

I'll bet Smile

Grey

--
The technical axiom that nothing is impossible sinisterly implies the
pitfall corollary that nothing is ridiculous.
- http://www.greywyvern.com/orca#search - Orca Search: Full-featured
spider and site-search engine
 >> Stay informed about: mod_rewrite help 
Back to top
Login to vote
spam19

External


Since: May 08, 2004
Posts: 952



(Msg. 8) Posted: Mon Aug 14, 2006 2:39 pm
Post subject: Re: mod_rewrite help [Login to view extended thread Info.]
Archived from groups: per prev. post (more info?)

And lo, Karl Groves didst speak in alt.www.webmaster:

> GreyWyvern <spam RemoveThis @greywyvern.com> wrote:
>
>> And lo, Karl Groves didst speak in alt.www.webmaster:
>>
>>> GreyWyvern <spam RemoveThis @greywyvern.com> wrote:
>>>
>>>> www.example.com/?id=foo
>>>> to:
>>>> www.example.com/foo
>>>>
>>>> RewriteEngine On
>>>>
>>>> RewriteCond %{QUERY_STRING} ^id=(.*)$
>>>> RewriteRule ^$ /%1? [R=301]
>>>
>>> Didna work. Got a 404
>>
>> I tested it on my own server before posting it here, and it WFM. Do
>> you get a 404 when you go to www.example.com/foo directly?
>
> Yeah.
> What's weird is now, if I go to www.example.com/?id=foo it redirects me
> to
> www.example.com/foo

I'm confused then, because I thought that's what you wanted.

Grey

--
The technical axiom that nothing is impossible sinisterly implies the
pitfall corollary that nothing is ridiculous.
- http://www.greywyvern.com/orca#search - Orca Search: Full-featured
spider and site-search engine
 >> Stay informed about: mod_rewrite help 
Back to top
Login to vote
spam19

External


Since: May 08, 2004
Posts: 952



(Msg. 9) Posted: Mon Aug 14, 2006 3:12 pm
Post subject: Re: mod_rewrite help [Login to view extended thread Info.]
Archived from groups: per prev. post (more info?)

And lo, Karl Groves didst speak in alt.www.webmaster:
> GreyWyvern <spam.DeleteThis@greywyvern.com> wrote:
>> And lo, Karl Groves didst speak in alt.www.webmaster:
>>> GreyWyvern <spam.DeleteThis@greywyvern.com> wrote:
>>>> And lo, Karl Groves didst speak in alt.www.webmaster:
>>>>> GreyWyvern <spam.DeleteThis@greywyvern.com> wrote:
>>>>>
>>>>>> www.example.com/?id=foo
>>>>>> to:
>>>>>> www.example.com/foo
>>>>>>
>>>>>> RewriteEngine On
>>>>>>
>>>>>> RewriteCond %{QUERY_STRING} ^id=(.*)$
>>>>>> RewriteRule ^$ /%1? [R=301]
>>>>>
>>>>> Didna work. Got a 404
>>>>
>>>> I tested it on my own server before posting it here, and it WFM. Do
>>>> you get a 404 when you go to www.example.com/foo directly?
>>>
>>> Yeah.
>>> What's weird is now, if I go to www.example.com/?id=foo it redirect
>> s me
>>> to
>>> www.example.com/foo
>>
>> I'm confused then, because I thought that's what you wanted.
>
> Well, now the PHP script isn't liking the lack of the ID in the URL.

You mean the PHP script is still looking for the id in the query string?
Perhaps we have things backwards then and really you wish to *rewrite*
www.example.com/foo to www.example.com/?id=foo

In that case, we'd do:

RewriteEngine On

RewriteRule ^([^/]+)$ /?id=$1 [L]


In cases where you have enabled extension mapping, you might grab the file
extension text too if a file named foo.php or foo.html (etc.) actually
exists. You can bypass that using:

RewriteEngine On

RewriteCond %{REQUEST_URI} ^/([^/]+)$
RewriteRule ^.*$ /?id=%1 [L]


Grey

--
The technical axiom that nothing is impossible sinisterly implies the
pitfall corollary that nothing is ridiculous.
- http://www.greywyvern.com/orca#search - Orca Search: Full-featured
spider and site-search engine
 >> Stay informed about: mod_rewrite help 
Back to top
Login to vote
spam19

External


Since: May 08, 2004
Posts: 952



(Msg. 10) Posted: Mon Aug 14, 2006 3:37 pm
Post subject: Re: mod_rewrite help [Login to view extended thread Info.]
Archived from groups: per prev. post (more info?)

And lo, Karl Groves didst speak in alt.www.webmaster:

> GreyWyvern <spam RemoveThis @greywyvern.com> wrote:
>
>> You mean the PHP script is still looking for the id in the query
>> string? Perhaps we have things backwards then and really you wish to
>> *rewrite* www.example.com/foo to www.example.com/?id=foo
>>
>> In that case, we'd do:
>>
>> RewriteEngine On
>>
>> RewriteRule ^([^/]+)$ /?id=$1 [L]
>
> Now www.example.com/foo gives an HTTP 500 error

All I can say is that it WFM Neutral Perhaps you should specify what file you
wish to rewrite to:

RewriteEngine On

RewriteRule ^([^/]+)$ index.php?id=$1 [L]


Grey

--
The technical axiom that nothing is impossible sinisterly implies the
pitfall corollary that nothing is ridiculous.
- http://www.greywyvern.com/orca#search - Orca Search: Full-featured
spider and site-search engine
 >> Stay informed about: mod_rewrite help 
Back to top
Login to vote
spamblocked1

External


Since: Sep 19, 2003
Posts: 3499



(Msg. 11) Posted: Mon Aug 14, 2006 7:42 pm
Post subject: Re: mod_rewrite help [Login to view extended thread Info.]
Archived from groups: per prev. post (more info?)

Fleeing from the madness of the jungle
Karl Groves <karl.DeleteThis@NOSPAMkarlcore.com> stumbled into news:alt.www.webmaster
and said:

> ...
> What's weird is now, if I go to www.example.com/?id=foo it redirects me
> to
> www.example.com/foo

isn't that what you asked for?

--
William Tasso

http://williamtasso.com/words/what-is-usenet.asp
 >> Stay informed about: mod_rewrite help 
Back to top
Login to vote
usenet36

External


Since: Jan 25, 2005
Posts: 235



(Msg. 12) Posted: Mon Aug 14, 2006 8:43 pm
Post subject: Re: mod_rewrite help [Login to view extended thread Info.]
Archived from groups: per prev. post (more info?)

On Mon, 14 Aug 2006 13:45:43 -0500, Karl Groves put finger to keyboard
and typed:

>Well, now the PHP script isn't liking the lack of the ID in the URL.

How are you parsing it?

This is a script snippet that I use when I need a page to work either
with "traditional" GET variables or with URL parsing:

<?
$id_get = $_GET['id']; // www.example.com/?id=foo will yield 'foo'
$URL_split = explode("/", $_SERVER['SCRIPT_URL']);
$id_url = $URL_split[1]; // www.example.com/foo will yield 'foo'
if ($id_get) { $id = $id_get; }
elseif ($id_url) { $id = $id_url ; }
else { $id = "mydefaultvalue"; }
?>

and then work from there with your value of $id.

Mark
--
Please give me one! http://www.pleasegivemeone.com
 >> Stay informed about: mod_rewrite help 
Back to top
Login to vote
user94

External


Since: Sep 14, 2004
Posts: 2384



(Msg. 13) Posted: Mon Aug 14, 2006 9:59 pm
Post subject: Re: mod_rewrite help [Login to view extended thread Info.]
Archived from groups: per prev. post (more info?)

Karl Groves wrote

> Well, now the PHP script isn't liking the lack of the ID in the URL.

I'm guessing (half guessing, we discussed this recently) that you want
to lose "id=" in your URLs to keep (amongst others) Google sweet.

I was in a similar position, and got around it thus:

Change:

www.example.com/?id=foo

to:

www.example.com/?banana=foo

Then in the script that handles it, put this (or similar as appropriate)
near the top:

if(isset($banana)){$id = $banana;}

The script still gets its "id" values, those of banana.

--
Charles Sweeney
http://CharlesSweeney.com
 >> Stay informed about: mod_rewrite help 
Back to top
Login to vote
Display posts from previous:   
   Web Hosting and Web Master Forums (Home) -> Webmaster All times are: Pacific Time (US & Canada) (change)
Page 1 of 1

 
You can post new topics in this forum
You can reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum



[ Contact us | Terms of Service/Privacy Policy ]