Forum Moderators: phranque
I'd like to have one file for each of the pages, for all clubs; but to make it look like they are still in folders.
bit like this:
url.com/clubs/example/index.php
>to<
url.com/clubs/index.php?folder=example
The pages are index.php, news.php, photo.php and results.php
but results.php would need another variable (for the result number):
url.com/clubs/example/results123.html
>to<
url.com/clubs/result.php?folder=example&id=123
This all way beyond me, all I've got going so far is for the results bit result123.html to result.php?id=123 code =>
Options +FollowSymLinks
RewriteEngine on
RewriteRule result(.*)\.html$ /clubs/example/result.php?id=$1
Cheers
Ric
It looks like you are on the right track... Thanks for posting an example and what you are trying =).
url.com/clubs/index.php?folder=example
url.com/clubs/example/results123.html
>to<
url.com/clubs/result.php?folder=example&id=123
You could use this: (if example does not change, change from the regex to the actual word example.)
RewriteRule ^clubs/([^/]+)/(index\.html)?$ /index.php?folder=$1 [L]
RewriteRule ^clubs/([^/]+)/result([0-9]+)\.html$ /result.php?folder=$1&id=$2 [L]
([^/]+) = 1 or more of anything, except a slash.
(index\.html)? = index.html is optional so either / or /index.html will qualify.
([0-9]+) = 1 or more of the number 0 to 9
\. = A litteral .(dot) not 'anything except the ending of a line'
I would think about putting the code 'deeper' in your site to eliminate some processing overhead. You could do this by creating the directory 'example', which I am assuming is a club name, then using an htaccess file instead of content, like this:
In the directory /clubs/example/:
RewriteRule ^(index\.html)?$ /index.php?folder=example [L]
RewriteRule ^result([0-9]+)\.html$ /result.php?folder=example&id=$1 [L]
The biggest difference is in the main htaccess file, you will have to process all the way to the first letter after the second slash, for each request before a rule can truly qualify or fail. In the second example, you are already in the correct directory, so you reduce your variables by one and you can qualify or fail a rule by the first letter.
Hope this helps.
Justin
Added: The benefits of the second example may increase/decrease based on the number of actual directories you would need to have.
The first one =>
RewriteRule ^clubs/([^/]+)/(index\.html)?$ /index.php?folder=$1 [L]
RewriteRule ^clubs/([^/]+)/result([0-9]+)\.html$ /result.php?folder=$1&id=$2 [L]
([^/]+) = 1 or more of anything, except a slash.
(index\.html)? = index.html is optional so either / or /index.html will qualify.
([0-9]+) = 1 or more of the number 0 to 9
\. = A litteral .(dot) not 'anything except the ending of a line'
is exactly the thing I want. Yes example changes with every club too. You say ([0-9]) is 0 to 9, but there is potentially an infinate amount of results, any way to change that slightly?
Oh aye, I put this as a .htaccess file in the folder url.com/clubs/ but all I got were 404 errors. I did make a little addition to the htacces, but only where I had to rename files, here's my htacess that I tried =>
Options +FollowSymLinks
RewriteEngine on
RewriteRule ^clubs/([^/]+)/(index\.php)?$ /clubs/clubindex.php?folder=$1 [L]
RewriteRule ^clubs/([^/]+)/(news\.php)$ /clubs/clubnews.php?folder=$1 [L]
RewriteRule ^clubs/([^/]+)/(photo\.php)$ /clubs/clubphoto.php?folder=$1 [L]
RewriteRule ^clubs/([^/]+)/result([0-9]+)\.html$ /clubs/clubresult.php?folder=$1&id=$2 [L]
Ric
Welcome to WebmasterWorld!
If you put the code in the .htaccess file in the "/clubs" directory, then you'll need to remove "clubs/" from the patterns in your rewriterules. The local-URL-paths "seen" by RewriteRule are localized to the directory in which that rule resides, so "clubs/" will be stripped out of the URL by the time the .htaccess rules in the "/clubs" directory see the URL. This is the meaning of "per-directory rewrites". Also, the second set of parentheses appears to be superfluous in the first three rules.
So, your first rule should look like this:
RewriteRule ^([^/]+)/index\.php?$ /clubs/clubindex.php?folder=$1 [L]
Jim
Just to maybe explain my problem again, as maybe I've not done it right before.
[url.com...]
>to<
[url.com...]
and
[url.com...]
>to<
[url.com...]
I'm trying to put the htaccess file in the clubs directory, is this correct? I dont think it makes alot of difference, other than my code would have to be slightly different.
I have a directory of photos, news, etc. within the clubs/ directory, these are going to be effected by the rewrite rules. Is there some way of exculding some directories from the usual rewrite?
Also if there is a trailing slash missing on
[url.com...]
a 404 comes up, will this code fix that problem:
RewriteRule ^([^/]+)$ /clubs/$1/ [L]
# Fix missing trailing slash on any URL which does not contain a period
RewriteCond %{REQUEST_URI} !/$
RewriteCond %{REQUEST_URI} !\.
Rewriterule (.+) /$1/ [R=301,L]
Options +FollowSymLinks
RewriteEngine on
RewriteCond %{REQUEST_URI}!^clubs/admin/ [NC,OR]
RewriteCond %{REQUEST_URI}!^clubs/intro/ [NC,OR]
RewriteCond %{REQUEST_URI}!^clubs/photos/ [NC,OR]
RewriteCond %{REQUEST_URI}!^clubs/news/ [NC,OR]
RewriteCond %{REQUEST_URI}!^clubs/unc/ [NC,OR]
RewriteCond %{REQUEST_URI}!^clubs/bicc/ [NC]
RewriteRule ^([^/]+)/(index\.php)?$ /clubs/clubindex.php?folder=$1 [L]
RewriteRule ^([^/]+)/news\.php$ /clubs/clubnews.php?folder=$1 [L]
RewriteRule ^([^/]+)/photo\.php$ /clubs/clubphoto.php?folder=$1 [L]
RewriteRule ^([^/]+)/result\.php$ /clubs/clubresult.php?folder=$1 [L]
RewriteRule ^([^/]+)/result([0-9]+)?\.html$ /clubs/clubresult.php?folder=$1&id=$2 [L]
Its the conditions at the start. Any requests to www.url.com/clubs/unc (or any of the others) I dont want to be processed by the rewrite rules below it. With this code I've found that the admin condition lets me access the admin dir, but the other condititons dont seem to work. Any ideas?
Many thanks =D
Edit: The code is in the htaccess of the url.com/clubs/ folder. Cheers!
I would try removing the OR from your condition flags. By using OR, the conditions will not qualify. Generally speaking most (90%) of the time when you use a ! and multiple conditions, you will want to use the implicit AND, not OR. I would try to explain, but the only way it make any sense to me is to say it as a sentence, out loud... if the condition is not this and is not this...
That's the only thing I see with a quick glance, please post again if this does not help... and define exactly what you mean by 'does not work'.
Justin
I'm not sure what the REQUEST_URI brings back, so maybe its a problem with the clubs/bicc/ or bicc/ test for it?
I didnt know that the conditions only work for the rewrite after it; is there a way to have the conditions for all rewrite rules? or should I copy and paste them before every rewrite?
Sorry for all the questions :S
Options +FollowSymLinks
RewriteEngine on
#
# Skip next five rules if excluded subdirectory
RewriteRule ^clubs/(admin¦intro¦photos¦news¦unc¦bicc)/ - [S=5]
#
# Else not an excluded subdirectory -- process the following rules
RewriteRule ^([^/]+)/(index\.php)?$ /clubs/clubindex.php?folder=$1 [L]
RewriteRule ^([^/]+)/news\.php$ /clubs/clubnews.php?folder=$1 [L]
RewriteRule ^([^/]+)/photo\.php$ /clubs/clubphoto.php?folder=$1 [L]
RewriteRule ^([^/]+)/result\.php$ /clubs/clubresult.php?folder=$1 [L]
RewriteRule ^([^/]+)/result([0-9]+)?\.html$ /clubs/clubresult.php?folder=$1&id=$2 [L]
#
# Skip=5 lands here to continue with any other following rules
#
... more rules ...
Jim
It seems to only look at the first rule, and no matter if its true or false, doesnt go any further.
I made a slight edit to the first rule from above, it reads:
RewriteRule ^(admin¦intro¦photos¦news¦unc¦bicc)/ - [L]
Just removed the clubs/ as it is in the clubs folder.
Edit: I put the pipe characters in, but it doesnt show up on the forum.
I'm sorry, this is not clear. Please provide the full requested URL-path, the expected result, and the actual result so that we can proceed.
Just guessing, but if there's no trailing slash in the folder request, then the first rule would need to change to something like this:
RewriteRule ^([^/]+)(/(index\.php)?)?$ /clubs/clubindex.php?folder=$1 [L]
Jim
I want to go to: http://www.example.com/clubs/example/
This should using the rules point to: http://www.example.com/clubs/clubsindex.php?folder=example
Unless it is asking for any of these:
http://www.example.com/clubs/admin/
http://www.example.com/clubs/photos/
http://www.example.com/clubs/intro/
http://www.example.com/clubs/news/
http://www.example.com/clubs/bicc/
http://www.example.com/clubs/unc/
This is my htaccess at the moment and it is in the clubs folder (http://www.example.com/clubs/.htaccess):
Options +FollowSymLinks
RewriteEngine on
RewriteRule ^(admin¦intro¦photos¦news¦unc¦bicc)/ - [L]
RewriteRule ^([^/]+)/(index\.php)?$ /clubs/clubindex.php?folder=$1 [L]
RewriteRule ^([^/]+)/news\.php$ /clubs/clubnews.php?folder=$1 [L]
RewriteRule ^([^/]+)/photo\.php$ /clubs/clubphoto.php?folder=$1 [L]
RewriteRule ^([^/]+)/result\.php$ /clubs/clubresult.php?folder=$1 [L]
RewriteRule ^([^/]+)/result([0-9]+)?\.html$ /clubs/clubresult.php?folder=$1&id=$2 [L]
When this file is on the webserver to test it, all of the directories simply come up as normal, as if there were no htaccess file there at all, no redirects or anything.
As you've seen in my previous posts the end 5 rules all work when on their own, I just want to exclude (admin¦intro¦photos¦news¦unc¦bicc) from being redirected to the other files.
[edited by: jdMorgan at 5:03 pm (utc) on June 10, 2005]
[edit reason] Examplified. [/edit]
It's a standard file, usually located in the same directory as your access log.
> or what that rewrite option is?
RewriteOptions [httpd.apache.org]
[added] There's no obvious reason that your exclusions should not be working. This is an "easy" subject, normally. It's possible that I'm just not seeing something, since I pop in and out of here between phone calls and meetings... Or it's possible that some other code is interfering with it, or that the paths are not correct. I'm stumped.[/added]
Jim