After much experimentation, I got it!
RewriteEngine On
RewriteCond %{REQUEST_URI} ^/([a-zA-Z]+)\/([^\/]+)\/(.{0})$ RewriteRule / /mydir?topic=%2 [L] Roy
This is on my home computer with Windows 7 and Apache 2.2.
Once it works here I will upload to my host, Godaddy.
I have AllowOverride FileInfo and know the .htaccess file is being
read.
'mysite' is a <VIRTUALHOST> on my home computer. On the host it is
'site.com'.
DirectoryIndex is index.html index.php
I am just learning about Apache, mod_rewrite and regex.
I have a whole bunch of subdirectories (/mydir/xxx/) each with it's own
outdated index.html file.
I have written a single mydir/index.php?topic=xxx) to replace them
all
Directly calling http://mysite/mydir?topic=xxx works
fine.
I want traffic to
mysite/mydir/xxx/ where
the index.htmls are outdated
to rewrite to
mysite/mydir?topic=xxx the new general purpose
index.php
but images
mysite/mydir/xxx/img.jpg are still in xxx
and to leave
mysite/mydir?topic=xxx the correct call without
change
and
mysite/myotherdir should
not be effected
In mydir/.htaccess I tried:
RewriteEngine on
# for a directory, not an image file
RewriteCond %{REQUEST_URI}
-d
#doesn't have query
RewriteCond %{QUERY_STRING} ^$
RewriteRule ^mydir/(\w+)/?$ mydir?topic=$1 [L,R=301]
but it still gets mysite/mydir/xxx/index.html
instead of
mysite/mydir/index.php?topic=xxx
access.log shows:
"GET /mydir/xxx HTTP/1.1" 301 239
"GET /mydir/xxx/ HTTP/1.1" 200 4831
Could you point out my errors, please?
Roy Leroux
|