Forum Moderators: phranque

Message Too Old, No Replies

help for rewriterule

         

runawayz

7:46 am on Sep 24, 2009 (gmt 0)

10+ Year Member



hi everybody,
this is my problem.
I have an url like this:

[eco.something.com...]

and I would rewrite it as

[eco.something.com...]

As you can see I need to to use the number between comma and dot of the first url as a parameter value for "nid" into rewritten url.

I have tried with a rule like this

RewriteRule ^/news/economy/([a-zA-Z0-9\-]+),$.html /leaf.html?nsid=$1 [QSA,L]

But maybe I have misanderstood the use of $ and, obviously, the rule doesn't work... :(

Have you any idea to accomplish the right result?

Thanx in advance!

axiom

jdMorgan

1:35 pm on Sep 24, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



$1 through $9 refer to the matched contents of the first through ninth parenthesized sub-patterns in the rewriterule pattern. Therefore, you need to remove the first set of parentheses in your pattern, and then add a parenthesized pattern to 'catch' the characters between "," and "." in the requested URL-path.

Based on your example, Id suggest "^/news/economy/[a-zA-Z0-9\-]+,([^.]+)$\.html" to catch "one more characters not a period" following a comma and preceding a literal period (which must be escaped with a backslash as shown).

Also, if this code goes into .htaccess or into a <Directory> container inside httpd.conf or other server config file, then remove the leading slash from this pattern.

Please see the resources cited in our Forum Charter [webmasterworld.com] for more information.

Jim

runawayz

8:19 am on Sep 25, 2009 (gmt 0)

10+ Year Member



thanx for your answer. I tried your rule but it still doesn't function :(
I tried also to remove leading slash and to escape the comma with a backslash without any good result.
Th file I'm editing is the apache httpd.conf, maybe the problem are underscores in my urls. I'm going to check resources on forum charter in order to find a solution

thanx anyway,
rnwyz

jdMorgan

12:35 pm on Sep 25, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



If the code is in httpd.conf, but not inside a <Directory> container, then the leading slash is required.

It is not necessary to escape commas. If it were, I would have said so...

If this is the only rewriterule in the file, and you've just added it, then you'll need to set up and enable mod_rewrite by preceding your rule with:


Options +FollowSymLinks
RewriteEngine on

Jim

runawayz

1:05 pm on Sep 25, 2009 (gmt 0)

10+ Year Member



it's inside a <VirtualHost *> and the RewriteEngine was already on "on" because it's not the first rewrite rule for that VirtualHost.
There's also "Options +FollowSymLinks" in that file.
I retry, thanx a lot anyway, Jim.

Caterham

4:30 pm on Sep 25, 2009 (gmt 0)

10+ Year Member



You shouldn't mark the end of a string when .html to the right is expected in an input string.

^/news/economy/[a-zA-Z0-9\-]+,([^.]+)[b][red]$[/red][/b]\.html

[edited by: jdMorgan at 9:27 pm (utc) on Sep. 25, 2009]
[edit reason] emphasized error in red [/edit]

runawayz

9:37 am on Sep 28, 2009 (gmt 0)

10+ Year Member



hi Caterham,
so your purpose is to put the $ to the end of tha pattern?

something like this?
^/news/economy/[a-zA-Z0-9\-]+,([^.]+)\.html$

runawayz

1:12 pm on Sep 28, 2009 (gmt 0)

10+ Year Member



ok, now it works perfectly.
the problem was that first reg exp didn't "see" underscores into the first part of the url before comma. I added only a backslash before the underscore.
Now my rewriterule is:
RewriteRule ^/news/economy/[a-zA-Z0-9\_]+,([^.]+)\.html$ /leaf.html?nsid=$1 [QSA,L]

thanx everybody!
rnwyz