Welcome to WebmasterWorld Guest from 18.204.227.250

Forum Moderators: Ocean10000 & phranque

Message Too Old, No Replies

help with mod rewrite

how to regex this to that

     
2:56 am on Aug 31, 2003 (gmt 0)

New User

10+ Year Member

joined:July 4, 2003
posts:31
votes: 0


what should I do to make mod rewrite change this url:

[example.com...]

into:

[example.com...]

?

thank you in advance!

7:17 am on Aug 31, 2003 (gmt 0)

New User

10+ Year Member

joined:July 4, 2003
posts:31
votes: 0


I re-read older threads on this and also checked a tutorial or two to clear up some symbols, and came up with this:

RewriteCond %{REQUEST_URI}!^/community-
RewriteRule ^/community-([^-]*)-([0-9]*)-([0-9]*)-([^-]*)\.htm$ /community/index.php?action=$1;board=$2;threadid=$3;start=$4 [L]

I copied the [L] from a rule I read in another thread, but I'm not really sure what it is for... I'll look it up

please let me know if it's ok :)

7:22 am on Aug 31, 2003 (gmt 0)

Full Member

10+ Year Member

joined:Dec 9, 2002
posts:325
votes: 0


The L rule means stop processing rewrite rules after matching this line.
8:09 pm on Aug 31, 2003 (gmt 0)

New User

10+ Year Member

joined:July 4, 2003
posts:31
votes: 0


thank you jpjones :)

ok, I put those two lines in .htaccess in the root directory and tried it, but it didn't work, I get a 404

am I missing something? or is it not well written?

8:37 pm on Aug 31, 2003 (gmt 0)

Full Member

10+ Year Member

joined:Dec 9, 2002
posts:325
votes: 0


Try the following:


RewriteRule ^/community-d-([0-9]*)-([0-9]*)-new\.htm$ /community/index.php?board=$1;action=display;threadid=$2;start=new [L]

without the rewritecond rule, and see what happens.
Also, are you sure your hosting company allows rewrite rules in your .htaccess file.

JP

9:14 pm on Aug 31, 2003 (gmt 0)

Senior Member

WebmasterWorld Senior Member jdmorgan is a WebmasterWorld Top Contributor of All Time 10+ Year Member

joined:Mar 31, 2002
posts:25430
votes: 0


Anguz,

For use in .htaccess per-directory context, you'll need to remove the leading slash in the RewriteRule pattern:


RewriteCond %{REQUEST_URI} !^/community-
RewriteRule [b]^co[/b]mmunity-([^-]*)-([0-9]*)-([0-9]*)-([^-]*)\.htm$ /community/index.php?action=$1;board=$2;threadid=$3;start=$4 [L]

Also, note that your original Rule will not set "action" to "display", it will only copy the "d" in the original URI, so the result will be "action=d". jpjones' version addresses this problem.

Take a look at your raw error log or access log, and see what the output URI was that caused the 404. In general, badly-written mod_rewrite code or the mod_rewrite module being missing or not allowed will result in a 500-Server Error, so I suspect you are very close to a working rule.

If yu don't have access to your raw logs, then temporarily change the flags in the RewriteRule from [L] to [R=301,L]. This will make the rewritten URI visible in the address bar of your browser.

Jim

10:07 pm on Aug 31, 2003 (gmt 0)

New User

10+ Year Member

joined:July 4, 2003
posts:31
votes: 0


I see what you mean about the action var, I think I may use the actual value "display", instead of "d", cause there can be other actions taken in the url, so maybe it's better to leave them as they are

about the change you told me, I did it, but it still gave me a "HTTP 404 - File not found", so I'm guessing that mod rewrite may in fact not be ON in my account... I'll message my webhost asking about this

after I confirm it's enabled and I try again, I'll poast here to let you guys know if it worked or not :)

6:33 am on Sept 1, 2003 (gmt 0)

New User

10+ Year Member

joined:July 4, 2003
posts:31
votes: 0


hmmm... my webhost told me that it's enabled, but it's not working...

I don't understand :/