You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@httpd.apache.org by Roy <ro...@azleroux.com> on 2012/10/17 00:16:42 UTC
[users@httpd] Adding a query with rewrite
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
Re: [users@httpd] Adding a query with rewrite
Posted by Roy <ro...@azleroux.com>.
After much experimentation, I got it!
RewriteEngine On
RewriteCond %{REQUEST_URI} ^/([a-zA-Z]+)\/([^\/]+)\/(.{0})$
RewriteRule / /mydir?topic=%2 [L]
Roy
From: Roy
Sent: Tuesday, October 16, 2012 3:16 PM
To: users@httpd.apache.org
Subject: [users@httpd] Adding a query with rewrite
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