Author |
|
epsavit
Joined: 11 Nov 2011 Posts: 5
|
Posted: Fri 11 Nov '11 21:35 Post subject: mod_rewrite hyphens spaces and more problems |
|
|
hi everybody
i would like some help if its possible
the problem is i have an old url like this
activities.php?lang=bg&page=full category- name&com=comname
which i read through the query string like this
RewriteCond %{QUERY_STRING} lang=(.*)&page=(.*)&com=([a-z]+)$
and then with a rewrite rule i turn it into a simple url like this
RewriteRule activities.php?$ "/foldername/activities/%1/0/0/%2/%3\.html?" [R=302,L]
and the end result is
The requested URL /activities/bg/0/0/%20name/comname.html was not found on this server.
so from page=full category- name i get only the last part > name
the problem is the spaces and hyphen on the "page=full category- name"
so i changed the query string reference like
RewriteCond %{QUERY_STRING} lang=(.*)&page=([a-z- ]+)&com=(.*)$ in order to include the spaces and hyphens.
but that change produces Internal Server Error.
the variable named page sometimes contains spaces and sometimes it doesnt.
can someone tell me what am i doing wrong ?
thanks |
|
Back to top |
|
glsmith Moderator
Joined: 16 Oct 2007 Posts: 2268 Location: Sun Diego, USA
|
Posted: Fri 11 Nov '11 21:45 Post subject: |
|
|
Shouldn't that be $1, $2, etc.? not %1, %2 etc?
I'm no Rewrite expert, quite the opposite. |
|
Back to top |
|
epsavit
Joined: 11 Nov 2011 Posts: 5
|
Posted: Fri 11 Nov '11 21:52 Post subject: |
|
|
hi
no thats the case inside a rewrite rule but when you gather data from a condition you reference it with % |
|
Back to top |
|
glsmith Moderator
Joined: 16 Oct 2007 Posts: 2268 Location: Sun Diego, USA
|
Posted: Fri 11 Nov '11 23:27 Post subject: Re: mod_rewrite hyphens spaces and more problems |
|
|
epsavit wrote: | RewriteRule activities.php?$ "/foldername/activities/%1/0/0/%2/%3\.html?" [R=302,L]
|
Well again, looking at RewriteRule in the docs, I see $1, $2, etc.
http://httpd.apache.org/docs/2.2/mod/mod_rewrite.html
Quote: | RewriteRule backreferences: These are backreferences of the form $N (0 <= N <= 9), which provide access to the grouped parts (in parentheses) of the pattern, from the RewriteRule which is subject to the current set of RewriteCond conditions.. |
To that matter, I see no %x encodings anywhere except for stuff like %{HTTP_USER_AGENT} or %{LA-U:variable}. |
|
Back to top |
|
epsavit
Joined: 11 Nov 2011 Posts: 5
|
Posted: Sat 12 Nov '11 0:06 Post subject: |
|
|
RewriteCond backreferences: These are backreferences of the form %N (1 <= N <= 9), which provide access to the grouped parts (again, in parentheses) of the pattern, from the last matched RewriteCond in the current set of conditions.
coming straight from the page you referenced |
|
Back to top |
|
glsmith Moderator
Joined: 16 Oct 2007 Posts: 2268 Location: Sun Diego, USA
|
Posted: Sat 12 Nov '11 0:33 Post subject: |
|
|
True, you got me there, but you are using them with "RewriteRule", not "RewriteCond", per your first post. RewriteRule uses $(1-9)
epsavit wrote: | RewriteRule activities.php?$ "/foldername/activities/%1/0/0/%2/%3\.html?" [R=302,L]
|
|
|
Back to top |
|
epsavit
Joined: 11 Nov 2011 Posts: 5
|
Posted: Sat 12 Nov '11 2:04 Post subject: |
|
|
yes but i am referencing groups from the condition. as it says in the apache documentation : from the last matched RewriteCond in the current set of conditions. trust me this is the right way. the problem is with the empty space and the hyphen. |
|
Back to top |
|
glsmith Moderator
Joined: 16 Oct 2007 Posts: 2268 Location: Sun Diego, USA
|
Posted: Sat 12 Nov '11 3:10 Post subject: |
|
|
well, to me it looks like it is somehow oddly working on %1 & %3, but it is wanting to change %2 to %20, a URL (space), instead of what it should be replacing that with.
Just curious, did you try it? It cannot hurt, but you probably know rewriting better than I. I think the docs are iffy here, cause it says one thing, then another, then reiterates what it first said.
RewriteRule backreferences: These are backreferences of the form $N (0 <= N <= 9), which provide access to the grouped parts (in parentheses) of the pattern, from the RewriteRule which is subject to the current set of RewriteCond conditions.. which is the case here as far as I can see and intemperate.
I have not yet found an example for RewriteRule using %N, doesn't mean it cannot be done, just is an indicator to me.
That is just my take. James or Steffen or someone else I am sure will be able to help. |
|
Back to top |
|
James Blond Moderator
Joined: 19 Jan 2006 Posts: 7364 Location: Germany, Next to Hamburg
|
Posted: Sat 12 Nov '11 8:04 Post subject: |
|
|
Well Gregg is right. There should be a $1 and $2 and so on.
simple rewrite rule from a cms where all stuff is appended to page=
Code: |
RewriteEngine on
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule (.*) index.php?page=$1 [QSA]
|
so example.com/foo/bar/
becomes
example.com/index.php?page=/foo/bar
---- edit ---
maybe it sounds boring, but turning on the rewrite log with the highest debug mode some times works wonders.
Also I recommend
if you know german than http://www.modrewrite.de/
else
http://www.modrewrite.com/
on http://www.modrewrite.com/ the beginner guide is good and on the forum there are real experts for rewriting.
It might be frustrating to be send somewhere else, but we know about apache and many other sutff, but mod rewrite is a topic for itself. And some kinda how we already have 340 topics about those stuff in the this forum.
if you still have a question than please ask again. |
|
Back to top |
|
epsavit
Joined: 11 Nov 2011 Posts: 5
|
Posted: Sat 12 Nov '11 11:14 Post subject: |
|
|
hi and thanks for the effort
in my case referencing groups from the conditional statement with $ doesnt help as $1,$2 and so on its empty because it searches inline at the current rewrite rule. just to be on the safe side tried that and got nothing. i'll give it a try at that other forum you suggested. rewrite log is empty cause i get internal server error.
thanks |
|
Back to top |
|