Forum Moderators: phranque
I would like to rewrite:
http://www.example.com/vienna*
http://www.example.com/vienna*/
http://www.example.com/visit/vienna* - only this works, going to the right directory
http://www.example.com/visit/vienna*/
* - means any character
to
www.example.com/visit/index.php?cat=19 (showing one of the urls above)
My rewrite script (first two lines should apply)
RewriteEngine on
RewriteRule ^(visit/)?(vienna¦wien)(.*)/?$ /visit/index.php?cat=19&main [L]
RewriteCond %{HTTP_HOST} ^(www.)?example.com$ [OR]
RewriteCond %{HTTP_HOST} ^(www.)?example1.com$
RewriteCond %{QUERY_STRING} !^id=
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^/]*)/?$ /index.php?id=$1$2 [QSA]
PROBLEM
When I use [R,L] at the first line, everything works perfectly for all 4 urls (as it is a redirection). But when I use [L] relative paths for style and images in coppermine gallery are not found properly.
How to avoid this? Is it possible? It may work with RewriteBase, but I wasn't able to solve it successfully. Rest part of the htaccess script is for another purpose which is working fine and I hope it doesn't influence the first line. I cannot change relative paths as the simplescript.com security updates always change the installation to the previous state (using relative paths everywhere in coppermine gallery).
Any help really appreciated.
[edited by: jatar_k at 3:14 pm (utc) on June 30, 2008]
[edit reason] please use example.com [/edit]
For now, add [R=301,L] on the end instead, so that it becomes a redirect. Check what the URL changes to in your browser. It will not "work". We are just changing it temporarily to see what is being requested inside the server. The only way to do that is to temporarily expose it.
I suspect that the $1 is the wrong thing to be using. Maybe it needs to be $2 or something. I never remember which way to count the brackets and always end up having to do a little test to find out again.
Here, $1 will contain the entire local URL-path to the image file's directory. $2 will contain only the final URL-path-part (the lowest-level subdirectory name), $3 will contain the image's filename and filetype, and $4 will contain the image's filetype only.
Jim
Perhaps I should rephrase:
RewriteEngine On
RewriteRule ^(.*)/$ index.php?pic=$1
RewriteRule ^[^/.]+\.(jpg¦gif¦png¦jpeg)$ %{REQUEST_URI}/ [R=301,L]
So I'm using the above rule to rewrite files that look like this:
www.mySite.com/mainFolder/subFolder/index.php?pic=1.jpg
to look like this:
www.mySite.com/mainFolder/subFolder/1.jpg/
This rules works great. The problem I am having is that I would prefer to put the .htaccess file that I currently put in mainFolder, in subFolder, so that I can apply this any other folders that are created later on, without having to add .htaccess files, because the people who will be creating the folders in the future lack the technical abilities to create and write .htaccess files.
Is there a rule that will allow me to put the above .htaccess file, which currently resides in subFolder, into mainFolder, and still have these rules work?
Index.php resides in subFolder, by the way.
It takes a URL request and translates that to an internal filepath and fetches the content from there.
RewriteEngine On
RewriteRule ^[b](([^/]+/)*)/[/b]([^/.]+\.(jpe?g¦gif¦png))$ /$1index.php?pic=$3 The bolded part is that which stores the folder path to the image and makes the code portable to other higher folders.