Welcome to HostingForumz.com!
FAQFAQ   SearchSearch      ProfileProfile    Private MessagesPrivate Messages   Log inLog in

mod_rewrite returns 404 not found error

 
   Web Hosting Problem Solving Community! (Home) -> Apache RSS
Related Topics:
Submitting a form returns a 404 error - Hello, I think I have a on my server. On all web sites hosted, there is the same error. When I submit a form, I get a 404 error message, although the was sent and received properly. Hitting F5 on my browser displays the..

Apache Tomcat returns HTTP 502 response error - Hi Guys, I am having some on the Tomcat (or the Servlet), can anyone please help? Here is how I deploy my Apache Tomcat Servlet The is like this: 1. startup both Apache and Tomcat 2. can access..

[bug] Saving .htaccess using uft-8 returns an "Internal Se.. - If you save the .htaccess file using or Windows 1252 it works fine. But if you use utf-8 and universal encoding, Apache triggers an Server I have tried several hours creating some rules, and when I found..

mod_rewrite example? - I've been looking through the info from here: I still dont how to make something like the Get rewritten to say:..

help please about mod_rewrite - Hello...i needed about to redirect all user something like to using an .htacces file with the following code but it doesn't work! Can anyone help me? file .htacces contents ..
Next:  Need More Impact on Your Website?  
Author Message
freech

External


Since: Feb 17, 2008
Posts: 8



(Msg. 1) Posted: Sun Feb 17, 2008 4:02 am
Post subject: mod_rewrite returns 404 not found error
Archived from groups: alt>apache>configuration (more info?)

hi guys, tried to make url rewrite like:
www.abc.com/show.php?tid=1 into www.abc.com/show/1

while encountered 404 error, please help:

<VirtualHost >
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{HTTP_HOST} ^www.abc.com
RewriteCond %{REQUEST_URI} !^index\.php$
RewriteCond %{REQUEST_URI} \.php$
RewriteRule (.*)\.php$ http://www.abc.com$1 [R]

RewriteCond %{HTTP_HOST} !^www.abc.com
RewriteRule ^(.+) %{HTTP_HOST} [C]
RewriteRule ^tid/([0-9]+)/$ /show.php?tid=$1 [L]

</IfModule>
</VirtualHost>

after restart apache, the url turns into: www.abc.com/show?tid=1
with a reported 404 not found error.

would you please comment? thanks !

 >> Stay informed about: mod_rewrite returns 404 not found error 
Back to top
Login to vote
Singh

External


Since: Feb 14, 2008
Posts: 2



(Msg. 2) Posted: Sun Feb 17, 2008 4:32 pm
Post subject: Re: mod_rewrite returns 404 not found error [Login to view extended thread Info.]
Archived from groups: per prev. post (more info?)

On Feb 17, 7:02 am, freech <hifre....DeleteThis@gmail.com> wrote:
> hi guys, tried to make url rewrite like:www.abc.com/show.php?tid=1intowww.abc.com/show/1
>
> while encountered 404 error, please help:
>
> <VirtualHost >
>     <IfModule mod_rewrite.c>
>     RewriteEngine On
>     RewriteCond %{HTTP_HOST} ^www.abc.com
>     RewriteCond %{REQUEST_URI} !^index\.php$
>     RewriteCond %{REQUEST_URI} \.php$
>     RewriteRule (.*)\.php$http://www.abc.com$1[R]
>
>     RewriteCond %{HTTP_HOST} !^www.abc.com
>     RewriteRule ^(.+) %{HTTP_HOST} [C]
>     RewriteRule ^tid/([0-9]+)/$ /show.php?tid=$1 [L]
>
>     </IfModule>
> </VirtualHost>
>
> after restart apache, the url turns into:  www.abc.com/show?tid=1
> with a reported 404 not found error.
>
> would you please comment? thanks !

Not sure if it will help ur scenerio but if this is the only url u
want to redirect then u can easily do it in the "show.php" itself as u
r passing the variable name and value so all u have to do is use
"header" function in this php to make the url u need.

Thanks
Singh

 >> Stay informed about: mod_rewrite returns 404 not found error 
Back to top
Login to vote
phantom

External


Since: Aug 23, 2007
Posts: 66



(Msg. 3) Posted: Sun Feb 17, 2008 6:04 pm
Post subject: Re: mod_rewrite returns 404 not found error [Login to view extended thread Info.]
Archived from groups: per prev. post (more info?)

"freech" <hifreedo DeleteThis @gmail.com> wrote in message
news:5f0d23d6-58df-4c08-885b-824ac081d049@i29g2000prf.googlegroups.com...
> hi guys, tried to make url rewrite like:
> www.abc.com/show.php?tid=1 into www.abc.com/show/1
>
> while encountered 404 error, please help:
>
> <VirtualHost >
> <IfModule mod_rewrite.c>
> RewriteEngine On
> RewriteCond %{HTTP_HOST} ^www.abc.com
Host must start www<something>abc<something>com
OK, but probably not quite what you meant, this maybe:
RewriteCond %{HTTP_HOST} ^www\.abc\.com$

> RewriteCond %{REQUEST_URI} !^index\.php$
Always true, REQUEST_URI will *always* start with a slash, you probably
wanted:
RewriteCond %{REQUEST_URI} !^/index\.php$

> RewriteCond %{REQUEST_URI} \.php$
> RewriteRule (.*)\.php$ http://www.abc.com$1 [R]
This rule will indeed rewrite
/show.php to http://www.abc.com/show
as you have not specified any query string in the right hand side, the
original will be preserved, making http://www.abc.com/show.php?tid=1 ->
http://www.abc.com/show?tid=1

Try adding
RewriteCond %{QUERY_STRING} &?tid=(.+)&?
and changing the rule to be:
RewriteRule (.*)\.php$ http://www.abc.com$1/%1? [R]
 >> Stay informed about: mod_rewrite returns 404 not found error 
Back to top
Login to vote
freech

External


Since: Feb 17, 2008
Posts: 8



(Msg. 4) Posted: Tue Feb 19, 2008 5:17 am
Post subject: Re: mod_rewrite returns 404 not found error [Login to view extended thread Info.]
Archived from groups: per prev. post (more info?)

Dear Phantom,

thanks for your nice reply, according to your suggestion I have
adjusted the rules like:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{HTTP_HOST} ^www\.abc\.com$
RewriteCond %{REQUEST_URI} !^/index\.php$
RewriteCond %{REQUEST_URI} \.php$
RewriteCond %{QUERY_STRING} &?tid=(.+)&?
RewriteRule (.*)\.php$ http://www.abc.com$1/%1? [R]
</IfModule>

I'm glad to see, now the link already be referred to : from
www.abc.com/show.php?tid=1 to www.abc.com/show/1, which is great.
But the 404 not found error still exists, here I attached the log:

[18/Feb/2008:22:20:15 +0800] [www.abc.com/sid#a01f538][rid#a17d938/
initial] (2) init rewrite engine with requested uri /show.php
[18/Feb/2008:22:20:15 +0800] [www.abc.com/sid#a01f538][rid#a17d938/
initial] (3) applying pattern '(.*)\.php$' to uri '/show.php'
[18/Feb/2008:22:20:15 +0800] [www.abc.com/sid#a01f538][rid#a17d938/
initial] (2) rewrite '/show.php' -> 'http://www.abc.com/show/177?'
[18/Feb/2008:22:20:15 +0800] [www.abc.com/sid#a01f538][rid#a17d938/
initial] (3) split uri=http://www.abc.com/show/177? -> uri=http://
www.abc.com/show/177, args=<none>
[18/Feb/2008:22:20:15 +0800] [www.abc.com/sid#a01f538][rid#a17d938/
initial] (2) explicitly forcing redirect with http://www.abc.com/show/177
[18/Feb/2008:22:20:15 +0800] [www.abc.com/sid#a01f538][rid#a17d938/
initial] (1) escaping http://www.abc.com/viewblog/177 for redirect
[18/Feb/2008:22:20:15 +0800] [www.abc.com/sid#a01f538][rid#a17d938/
initial] (1) redirect to http://www.abc.com/show/177 [REDIRECT/302]
[18/Feb/2008:22:20:15 +0800] [www.abc.com/sid#a01f538][rid#a1cf638/
initial] (2) init rewrite engine with requested uri /show/177
[18/Feb/2008:22:20:15 +0800] [www.abc.com/sid#a01f538][rid#a1cf638/
initial] (3) applying pattern '(.*)\.php$' to uri '/show/177'
[18/Feb/2008:22:20:15 +0800] [www.abc.com/sid#a01f538][rid#a1cf638/
initial] (1) pass through /show/177
[18/Feb/2008:22:20:15 +0800] [www.abc.com/sid#a01f538][rid#a179928/
subreq] (2) init rewrite engine with requested uri /show/177
[18/Feb/2008:22:20:15 +0800] [www.abc.com/sid#a01f538][rid#a179928/
subreq] (1) pass through /show/177
[18/Feb/2008:22:20:15 +0800] [www.abc.com/sid#a01f538][rid#a1741b8/
initial/redir#1] (2) init rewrite engine with requested uri /
missing.htm
[18/Feb/2008:22:20:15 +0800] [www.abc.com/sid#a01f538][rid#a1741b8/
initial/redir#1] (3) applying pattern '(.*)\.php$' to uri '/
missing.htm'
[18/Feb/2008:22:20:15 +0800] [www.abc.com/sid#a01f538][rid#a1741b8/
initial/redir#1] (1) pass through /missing.htm

can anyone lend me a hand?




On 2ÔÂ18ÈÕ, ÉÏÎç5ʱ12·Ö, "phantom" <nob....DeleteThis@blueyonder.invalid> wrote:
> "freech" <hifre....DeleteThis@gmail.com> wrote in message
>
> news:5f0d23d6-58df-4c08-885b-824ac081d049@i29g2000prf.googlegroups.com...> hi guys, tried to make url rewrite like:
> >www.abc.com/show.php?tid=1intowww.abc.com/show/1
>
> > while encountered 404 error, please help:
>
> > <VirtualHost >
> > <IfModule mod_rewrite.c>
> > RewriteEngine On
> > RewriteCond %{HTTP_HOST} ^www.abc.com
>
> Host must start www<something>abc<something>com
> OK, but probably not quite what you meant, this maybe:
> RewriteCond %{HTTP_HOST} ^www\.abc\.com$
>
> > RewriteCond %{REQUEST_URI} !^index\.php$
>
> Always true, REQUEST_URI will *always* start with a slash, you probably
> wanted:
> RewriteCond %{REQUEST_URI} !^/index\.php$
>
> > RewriteCond %{REQUEST_URI} \.php$
> > RewriteRule (.*)\.php$http://www.abc.com$1[R]
>
> This rule will indeed rewrite
> /show.php tohttp://www.abc.com/show
> as you have not specified any query string in the right hand side, the
> original will be preserved, makinghttp://www.abc.com/show.php?tid=1->http://www.abc.com/show?tid=1
>
> Try adding
> RewriteCond %{QUERY_STRING} &?tid=(.+)&?
> and changing the rule to be:
> RewriteRule (.*)\.php$http://www.abc.com$1/%1?[R]
 >> Stay informed about: mod_rewrite returns 404 not found error 
Back to top
Login to vote
freech

External


Since: Feb 17, 2008
Posts: 8



(Msg. 5) Posted: Tue Feb 19, 2008 7:07 am
Post subject: Re: mod_rewrite returns 404 not found error [Login to view extended thread Info.]
Archived from groups: per prev. post (more info?)

cool!!!
with you suggested, I modified the rules as:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{HTTP_HOST} ^www\.abc\.com$
RewriteCond %{REQUEST_URI} !^/index\.php$
RewriteCond %{REQUEST_URI} \.php$
RewriteCond %{QUERY_STRING} &?tid=(.+)&?
RewriteRule (.*)\.php$ http://www.abc.com$1/%1? [R]
RewriteRule ^/show/(.+)/?$ /show.php?tid=$1 [L]
</IfModule>

and now it works pretty well.

To completely understand this part, I have following to ask:
1. what should I do if I have parameters in a url like:
www.abc.com/show.php?tid=1&rid=a&zid=ab12 while I want to turn it
into: www.abc.com/show/1/a/ab12
tid only allows numbers; rid allows letters; zid maybe a mix.
how to write the rule? and will the php automatically recognize
from the url, tid should be 1, instead of a?
after learn how to deal with above case, I think I could master
this rule Razz

2. after I turned this mod_rewrite on, found I have to change my
previous links in the pages.
for e.g. previous I will write the a link in page like <a
href="abc.php>abc</a>, now have to modify it into <a href="/
abc.php>abc</a>
for images, have to do like <img src='./images/q.png' /> to <img
src='/images/q.png' />
I want to understand, will this changing affect the server's
response, which is better?

3. on browsing some webs, when place mouse on a link, on the IE status
bar will appears like "abc/123" instead of "abc.php?uid=123",
according to our current mod_rewrite request, does that mean I'd
better to to modify all the existing links as well?

All of your kind guidance are much appreciated.









On 2ÔÂ19ÈÕ, ÏÂÎç9ʱ43·Ö, "phantom" <nob....TakeThisOut@blueyonder.invalid> wrote:
> "freech" <hifre....TakeThisOut@gmail.com> wrote in message
>
> news:eff825f3-5644-4f3a-9b23-7e2c91b2cba7@s8g2000prg.googlegroups.com...
>
> > thanks for your nice reply, according to your suggestion I have
> > adjusted the rules like:
> > <IfModule mod_rewrite.c>
> > RewriteEngine On
> > RewriteCond %{HTTP_HOST} ^www\.abc\.com$
> > RewriteCond %{REQUEST_URI} !^/index\.php$
> > RewriteCond %{REQUEST_URI} \.php$
> > RewriteCond %{QUERY_STRING} &?tid=(.+)&?
> > RewriteRule (.*)\.php$http://www.abc.com$1/%1?[R]
> > </IfModule>
>
> > I'm glad to see, now the link already be referred to : from
> >www.abc.com/show.php?tid=1towww.abc.com/show/1, which is great.
> > But the 404 not found error still exists, here I attached the log:
>
> If you're getting a 404 that would suggest that you do not have a
> file/directory at
> <DOCUMENT_ROOT>/show/1
> or as your log suggests> rewrite '/show.php' -> 'http://www.abc.com/show/177?'
>
> a file/directory at
> <DOCUMENT_ROOT>/show/177
>
> I suspect you are going the wrong way, would the following be what you are
> actually trying to achieve:
>
> a user types in the URLhttp://www.abc.com/show/177this URL is then
> processed behind the scenes byhttp://www.abc.com/show.php?tid=177 without the user ever seeing this
> second url?
>
> which would be achieved with something like this:
> RewriteRule ^/show/(.+)/?$ /show.php?tid=$1 [L]
 >> Stay informed about: mod_rewrite returns 404 not found error 
Back to top
Login to vote
phantom

External


Since: Aug 23, 2007
Posts: 66



(Msg. 6) Posted: Tue Feb 19, 2008 1:43 pm
Post subject: Re: mod_rewrite returns 404 not found error [Login to view extended thread Info.]
Archived from groups: per prev. post (more info?)

"freech" <hifreedo.DeleteThis@gmail.com> wrote in message
news:eff825f3-5644-4f3a-9b23-7e2c91b2cba7@s8g2000prg.googlegroups.com...
> thanks for your nice reply, according to your suggestion I have
> adjusted the rules like:
> <IfModule mod_rewrite.c>
> RewriteEngine On
> RewriteCond %{HTTP_HOST} ^www\.abc\.com$
> RewriteCond %{REQUEST_URI} !^/index\.php$
> RewriteCond %{REQUEST_URI} \.php$
> RewriteCond %{QUERY_STRING} &?tid=(.+)&?
> RewriteRule (.*)\.php$ http://www.abc.com$1/%1? [R]
> </IfModule>
>
> I'm glad to see, now the link already be referred to : from
> www.abc.com/show.php?tid=1 to www.abc.com/show/1, which is great.
> But the 404 not found error still exists, here I attached the log:

If you're getting a 404 that would suggest that you do not have a
file/directory at
<DOCUMENT_ROOT>/show/1
or as your log suggests
> rewrite '/show.php' -> 'http://www.abc.com/show/177?'
a file/directory at
<DOCUMENT_ROOT>/show/177

I suspect you are going the wrong way, would the following be what you are
actually trying to achieve:

a user types in the URL http://www.abc.com/show/177 this URL is then
processed behind the scenes by
http://www.abc.com/show.php?tid=177 without the user ever seeing this
second url?

which would be achieved with something like this:
RewriteRule ^/show/(.+)/?$ /show.php?tid=$1 [L]
 >> Stay informed about: mod_rewrite returns 404 not found error 
Back to top
Login to vote
freech

External


Since: Feb 17, 2008
Posts: 8



(Msg. 7) Posted: Wed Feb 20, 2008 6:16 am
Post subject: Re: mod_rewrite returns 404 not found error [Login to view extended thread Info.]
Archived from groups: per prev. post (more info?)

Hi , any comments / directions are appreciated Smile

On 2ÔÂ19ÈÕ, ÏÂÎç11ʱ07·Ö, freech <hifre....TakeThisOut@gmail.com> wrote:
> cool!!!
> with you suggested, I modified the rules as:
> <IfModule mod_rewrite.c>
> RewriteEngine On
> RewriteCond %{HTTP_HOST} ^www\.abc\.com$
> RewriteCond %{REQUEST_URI} !^/index\.php$
> RewriteCond %{REQUEST_URI} \.php$
> RewriteCond %{QUERY_STRING} &?tid=(.+)&?
> RewriteRule (.*)\.php$http://www.abc.com$1/%1?[R]
> RewriteRule ^/show/(.+)/?$ /show.php?tid=$1 [L]
> </IfModule>
>
> and now it works pretty well.
>
> To completely understand this part, I have following to ask:
> 1. what should I do if I have parameters in a url like:www.abc.com/show.php?tid=1&rid=a&zid=ab12 while I want to turn it
> into: www.abc.com/show/1/a/ab12
> tid only allows numbers; rid allows letters; zid maybe a mix.
> how to write the rule? and will the php automatically recognize
> from the url, tid should be 1, instead of a?
> after learn how to deal with above case, I think I could master
> this rule Razz
>
> 2. after I turned this mod_rewrite on, found I have to change my
> previous links in the pages.
> for e.g. previous I will write the a link in page like <a
> href="abc.php>abc</a>, now have to modify it into <a href="/
> abc.php>abc</a>
> for images, have to do like <img src='./images/q.png' /> to <img
> src='/images/q.png' />
> I want to understand, will this changing affect the server's
> response, which is better?
>
> 3. on browsing some webs, when place mouse on a link, on the IE status
> bar will appears like "abc/123" instead of "abc.php?uid=123",
> according to our current mod_rewrite request, does that mean I'd
> better to to modify all the existing links as well?
>
> All of your kind guidance are much appreciated.
>
> On 2ÔÂ19ÈÕ, ÏÂÎç9ʱ43·Ö, "phantom" <nob....TakeThisOut@blueyonder.invalid> wrote:
>
> > "freech" <hifre....TakeThisOut@gmail.com> wrote in message
>
> >news:eff825f3-5644-4f3a-9b23-7e2c91b2cba7@s8g2000prg.googlegroups.com...
>
> > > thanks for your nice reply, according to your suggestion I have
> > > adjusted the rules like:
> > > <IfModule mod_rewrite.c>
> > > RewriteEngine On
> > > RewriteCond %{HTTP_HOST} ^www\.abc\.com$
> > > RewriteCond %{REQUEST_URI} !^/index\.php$
> > > RewriteCond %{REQUEST_URI} \.php$
> > > RewriteCond %{QUERY_STRING} &?tid=(.+)&?
> > > RewriteRule (.*)\.php$http://www.abc.com$1/%1?[R]
> > > </IfModule>
>
> > > I'm glad to see, now the link already be referred to : from
> > >www.abc.com/show.php?tid=1towww.abc.com/show/1, which is great.
> > > But the 404 not found error still exists, here I attached the log:
>
> > If you're getting a 404 that would suggest that you do not have a
> > file/directory at
> > <DOCUMENT_ROOT>/show/1
> > or as your log suggests> rewrite '/show.php' -> 'http://www.abc.com/show/177?'
>
> > a file/directory at
> > <DOCUMENT_ROOT>/show/177
>
> > I suspect you are going the wrong way, would the following be what you are
> > actually trying to achieve:
>
> > a user types in the URLhttp://www.abc.com/show/177thisURL is then
> > processed behind the scenes byhttp://www.abc.com/show.php?tid=177without the user ever seeing this
> > second url?
>
> > which would be achieved with something like this:
> > RewriteRule ^/show/(.+)/?$ /show.php?tid=$1 [L]
 >> Stay informed about: mod_rewrite returns 404 not found error 
Back to top
Login to vote
Display posts from previous:   
   Web Hosting Problem Solving Community! (Home) -> Apache 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 ]