Simple mod rewrite rule problem

Hi

I’m trying to rewrite a url.

Here’s how the url looks: http://helloworld.com/index.php?/plugin/tag/shade+tree

Here’s how I want it to look: http://helloworld.com/tag/shade-tree.html

Here’s my best effort:

RewriteRule ^tag/([a-zA-Z-]+)\\.html$ index.php?$1 [NC,L,QSA]

Don’t laugh, it looks like it should work to me. What I’m I doing wrong?

FJ,

RewriteRule ^[COLOR="Blue"]([/COLOR]tag/[a-zA-Z-]+)\\.html$ index.php?[COLOR="Blue"]plugin/[/COLOR]$1 [[COLOR="Red"]NC,[/COLOR]L,QSA]

From your description, it seemed that you were going backward but your code showed the proper direction. I made three changes to get it to work for you:

  1. Include tag/ in the atom.

  2. Include plugin/ before the atom in the redirection.

  3. REMOVE the No Case flag as it can only mess-up your RewriteRule AND you’ve already accounted for both cases in the character range definition. Just consider the No Case flag as useful ONLY when examining the {HTTP_HOST} because that variable is case insensitive.

Let us know how that works for you.

Regards,

DK

It doesn’t work.

If I go to: [noparse]http://helloworld.com/tag/shade-trees.html[/noparse]

it just takes me to my home page.

It might be because of the other rules that it doesn’t work. There’s a lot of rules wrote by the blog program in the .htaccess plus a few I scratched out or found.

Here’s the .htaccess


AddType x-mapp-php5 .php
AddType 'text/html; charset=UTF-8' html
# BEGIN s9y
Options -MultiViews
DirectoryIndex /index.php

RewriteEngine On
RewriteCond %{HTTP_HOST} ^www\\.(.+)$ [NC]
RewriteRule ^(.*)$ http://%1/$1 [R=301,L] 
RewriteBase /
[COLOR="Red"]RewriteRule ^(tag/[a-zA-Z-]+)\\.html$ index.php?plugin/$1 [L,QSA][/COLOR]
RewriteRule ^serendipity_admin.php serendipity_admin.php [NC,L,QSA]
RewriteRule ^((Entries/[0-9a-z\\.\\_!;,\\+\\-\\%]+\\.html)/?) index.php?/$1 [NC,L,QSA]
RewriteRule ^(([0-9]+)/Authors/[0-9a-z\\.\\_!;,\\+\\-\\%]+) index.php?/$1 [NC,L,QSA]
RewriteRule ^(Feeds/categories/([0-9;]+)-[0-9a-z\\.\\_!;,\\+\\-\\%]+\\.rss) index.php?/$1 [NC,L,QSA]
RewriteRule ^(Feeds/authors/([0-9]+)-[0-9a-z\\.\\_!;,\\+\\-\\%]+\\.rss) index.php?/$1 [NC,L,QSA]
RewriteRule ^(([0-9;]+)/[0-9a-z\\.\\_!;,\\+\\-\\%/]*\\.html) index.php?/$1 [NC,L,QSA]
RewriteRule ^archives([/A-Za-z0-9]+)\\.html index.php?url=/archives/$1.html [NC,L,QSA]
RewriteRule ^([0-9]+)[_\\-][0-9a-z_\\-]*\\.html index.php?url=$1-article.html [L,NC,QSA]
RewriteRule ^feeds/(.*) index.php?url=/feeds/$1 [L,QSA]
RewriteRule ^unsubscribe/(.*)/([0-9]+) index.php?url=/unsubscribe/$1/$2 [L,QSA]
RewriteRule ^approve/(.*)/(.*)/([0-9]+) index.php?url=approve/$1/$2/$3 [L,QSA]
RewriteRule ^delete/(.*)/(.*)/([0-9]+) index.php?url=delete/$1/$2/$3 [L,QSA]
RewriteRule ^(admin|entries)(/.+)? index.php?url=admin/ [L,QSA]
RewriteRule ^archive/? index.php?url=/archive [L,QSA]
RewriteRule ^(index|atom[0-9]*|rss|b2rss|b2rdf).(rss|rdf|rss2|xml) rss.php?file=$1&ext=$2
RewriteRule ^(plugin|plugin)/(.*) index.php?url=$1/$2 [L,QSA]
RewriteRule ^search/(.*) index.php?url=/search/$1 [L,QSA]
RewriteRule ^comments/(.*) index.php?url=/comments/$1 [L,QSA]
RewriteRule ^(serendipity\\.css|serendipity_admin\\.css)$ index.php?url=/$1 [L,QSA]
RewriteRule ^index\\.(html?|php.+) index.php?url=index.html [L,QSA]
RewriteRule ^htmlarea/(.*) htmlarea/$1 [L,QSA]
#RewriteCond %{REQUEST_URI} !-U
RewriteRule (.*\\.html?) index.php?url=/$1 [L,QSA]

<Files *.tpl.php>
    deny from all
</Files>

<Files *.tpl>
    deny from all
</Files>

<Files *.sql>
    deny from all
</Files>

<Files *.inc.php>
    deny from all
</Files>

<Files *.db>
    deny from all
</Files>

    #Leverage browser caching
    <FilesMatch "\\.(gif|flv|jpg|jpeg|png|gif|swf)$">
       FileETag -INode MTime Size
            # if you use ETags, you should unset Last-Modified
            Header unset Last-Modified
            Header set Cache-Control "max-age=604800, public, must-revalidate"
            Header set Expires "Thu, 31 Dec 2011 20:00:00 GMT"
        </FilesMatch>
        <FilesMatch "\\.(gz)$">
            FileETag None
            Header set Cache-Control "max-age=604800, public, must-revalidate"
            Header set Expires "Thu, 31 Dec 2011 20:00:00 GMT"
        </FilesMatch>
        <FilesMatch "\\.(js|css)$">
            FileETag None
            Header set Cache-Control "max-age=604800, public, must-revalidate"
            Header set Expires "Thu, 31 Dec 2011 20:00:00 GMT"
        </FilesMatch>

ErrorDocument 404 /404.html
ErrorDocument 400 /400.html
ErrorDocument 403 /403.html
ErrorDocument 500 /500.html

FJ,

Well, that’s a real mess! To test just the coding modification I provided, put all the following @#$% inside RewriteEngine off … RewriteEngine on directives.

BTW, your link went to another domain so I disabled it. You have something else going on which is not in the .htaccess, too.

Regards,

DK

yea i know but it works, only thing is i think it might be making to many caculations and slowing my site down. do you think so?

should i be putting the newer code on top or bottom or does it matter much where i insert the code?

the [L] that means that’s the end of that particular command?

helloworld is a real site …i should have known

i’m going to test out your code now…