You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@httpd.apache.org by Bob Smith <id...@gmail.com> on 2006/05/24 19:57:54 UTC
[users@httpd] mod_rewrite
I'm trying to remove two directories from the path of a website, but I just
can't seem to get the mod_rewrite syntax right.
I have a url coming in with a url like
http://www.mysite.com/directoryone/directorytwo/mypage.php?key=value
And I'm trying to redirect it to http://www.mysite.com/mypage.php?key=value
I'm pretty sure I have the 'where I want it to go' part right:
/$1 [QSA,R=301]
But the removing of the two directories isn't being nice. :(
Re: [users@httpd] mod_rewrite
Posted by Brian Rectanus <br...@gmail.com>.
On 5/24/06, Bob Smith <id...@gmail.com> wrote:
> On 5/24/06, Robert Ionescu <ro...@googlemail.com> wrote:
>
> > Bob Smith wrote:
> > > I'm trying to remove two directories from the path of a website, but I
> just
> > > can't seem to get the mod_rewrite syntax right.
> > >
> > > I have a url coming in with a url like
> > >
> http://www.mysite.com/directoryone/directorytwo/mypage.php?key=value
> > >
> > > And I'm trying to redirect it to
> http://www.mysite.com/mypage.php?key=value
> >
> > Are your directories constants? Or are they some kind variable?
> >
> > To force such an external redirect, you could use in your httpd.conf
> >
> > RewriteRule ^/directoryone/directorytwo/(mypage\.php)$
> /$1 [R=301,L]
>
>
> Yeah, the directories I want to remove will be the same. but the pages will
> be different (I'm hoping I don't have to do one for each individual page)
>
> I tried:
>
> RewriteEngine On
> RewriteRule ^/directoryone/directory/two/(.*)$ /$1
> [QSA,R=301]
>
> But that's throwing a 500 error
>
1) Don't forget your [L]ast flag.
[QSA,R=301,L]
2) Are your RewriteRules in a <Location>? If so, then the location
dir is already stripped before the RewriteRule gets called.
3) I am not sure QSA is doing what you want here (not tried it). Try these:
RewriteRule ^/directoryone/directorytwo/(.*)$ "/$1?" [QSA,R=301,L]
RewriteRule ^/directoryone/directorytwo/(.*)$ "/$1?%{QUERY_STRING}" [R=301,L]
4) Turn on debugging with RewriteLogLevel 2 and RewriteLog /some/log/file.
-B
---------------------------------------------------------------------
The official User-To-User support forum of the Apache HTTP Server Project.
See <URL:http://httpd.apache.org/userslist.html> for more info.
To unsubscribe, e-mail: users-unsubscribe@httpd.apache.org
" from the digest: users-digest-unsubscribe@httpd.apache.org
For additional commands, e-mail: users-help@httpd.apache.org
Re: [users@httpd] mod_rewrite
Posted by Bob Smith <id...@gmail.com>.
On 5/24/06, Robert Ionescu <ro...@googlemail.com> wrote:
>
> Bob Smith wrote:
> > I'm trying to remove two directories from the path of a website, but I
> just
> > can't seem to get the mod_rewrite syntax right.
> >
> > I have a url coming in with a url like
> > http://www.mysite.com/directoryone/directorytwo/mypage.php?key=value
> >
> > And I'm trying to redirect it to
> http://www.mysite.com/mypage.php?key=value
>
> Are your directories constants? Or are they some kind variable?
>
> To force such an external redirect, you could use in your httpd.conf
>
> RewriteRule ^/directoryone/directorytwo/(mypage\.php)$ /$1 [R=301,L]
Yeah, the directories I want to remove will be the same. but the pages will
be different (I'm hoping I don't have to do one for each individual page)
I tried:
RewriteEngine On
RewriteRule ^/directoryone/directory/two/(.*)$ /$1 [QSA,R=301]
But that's throwing a 500 error
Re: [users@httpd] mod_rewrite
Posted by Robert Ionescu <ro...@googlemail.com>.
Bob Smith wrote:
> I'm trying to remove two directories from the path of a website, but I just
> can't seem to get the mod_rewrite syntax right.
>
> I have a url coming in with a url like
> http://www.mysite.com/directoryone/directorytwo/mypage.php?key=value
>
> And I'm trying to redirect it to http://www.mysite.com/mypage.php?key=value
Are your directories constants? Or are they some kind variable?
To force such an external redirect, you could use in your httpd.conf
RewriteRule ^/directoryone/directorytwo/(mypage\.php)$ /$1 [R=301,L]
--
Robert
---------------------------------------------------------------------
The official User-To-User support forum of the Apache HTTP Server Project.
See <URL:http://httpd.apache.org/userslist.html> for more info.
To unsubscribe, e-mail: users-unsubscribe@httpd.apache.org
" from the digest: users-digest-unsubscribe@httpd.apache.org
For additional commands, e-mail: users-help@httpd.apache.org