Forum Moderators: phranque
instead of
[test.example.net...]
I've gotten rewrites to make it successfully rewrite to
[test.example.net...]
But, I want to strip out the "phpBB2" portion of the path to match existing pages that these will be replacing at the primary site (I don't want users to get lots of 404s when visiting bookmarked sites).
The .htaccess file in the phpBB2/ directory now looks like this:
RewriteEngine OnRewriteRule ^forums.html index.php [L]
RewriteRule ^viewforum([0-9]*)-([0-9]*).html viewforum.php?f=$1&start=$2
RewriteRule ^forum([0-9]*).html viewforum.php?f=$1&mark=topic
RewriteRule ^forum([0-9]*).html viewforum.php?f=$1
RewriteRule ^ptopic([0-9]*).html viewtopic.php?t=$1&view=previous
RewriteRule ^ntopic([0-9]*).html viewtopic.php?t=$1&view=next
RewriteRule ^ftopic([0-9]*)-([0-9]*)-([a-zA-Z]*)-([0-9]*).html viewtopic.php?t=$1&postdays=$2&postorder=$3&start=$4
RewriteRule ^ftopic([0-9]*)-([0-9]*)-([a-zA-Z]*)-highlight([0-9A-Za-z]*)-([0-9]*).html viewtopic.php?t=$1&postdays=$2&postorder=$3&highlight=$4&start=$5
RewriteRule ^ftopic([0-9]*)-([0-9]*).html viewtopic.php?t=$1&start=$2
RewriteRule ^ftopic([0-9]*)-highlight([0-9a-zA-Z]*).html viewtopic.php?t=$1&highlight=$2
RewriteRule ^ftopic([0-9]*).html viewtopic.php?t=$1
RewriteRule ^ftopic([0-9]*).html viewtopic.php?t=$1&start=$2&postdays=$3&postorder=$4&highlight=$5
RewriteRule ^post([0-9]*).html viewtopic.php?p=$1
RewriteRule ^print([0-9]*)-([0-9]*).html printview.php?t=$1&start=$2
RewriteRule ^viewprofile([0-9]*).html
profile.php?mode=viewprofile&u=$1
Again, this rewrites to
[test.example.net...]
instead of to
[test.example.net...]
What do I need to add to the .htaccess to remove the phpBB2? Do I need to move it into the parent directory?
Thanks in advance.
-Dariush Molavi
[edited by: jdMorgan at 4:32 pm (utc) on Dec. 1, 2004]
[edit reason] Removed specifics per TOS [/edit]
Welcome to WebmasterWorld!
Again, this rewrites to
[test.example.net...]
instead of to
[test.example.net...]One thing that will make the solution more obvious is to correct the wording of that concept. Your rules rewrite from http://test.example.net/phpBB2/forum7.html to a call to your viewforum.php script.
mod_rewrite works after an HTTP request is received by your server, but before any content is served or any scripts are invoked. Therefore, mod_rewrite modifies incoming URLs, and not the outgoing URLs seen on your pages in a browser.
Therefore, as long as "phpBB2" is not needed to make each forum's URL unique, you can remove the "phpBB2" from the on-page URLs generated by your scripts, and then use mod_rewrite to put "phpBB2" back into the path needed to call your scripts. As you surmised, the RewriteRules will have to be moved to the directory above phpBB2 in order for this to work.
I also note that you have two sets of duplicated patterns in your rules, and the second rule in each pair will never be invoked.
-and-
RewriteRule ^forum([0-9]*).html viewforum.php?f=$1&mark=topic
RewriteRule ^forum([0-9]*).html viewforum.php?f=$1
RewriteRule ^ftopic([0-9]*).html viewtopic.php?t=$1
RewriteRule ^ftopic([0-9]*).html viewtopic.php?t=$1&start=$2&postdays=$3&postorder=$4&highlight=$5
In both cases, the second rule will never be invoked, because the first one, if invoked, will change the URL before the second rule is tested.Also, if you always expect at least one number in the requested URL, you can use [0-9]+ instead of [0-9]* to achieve a slight speed increase.
Jim
Therefore, as long as "phpBB2" is not needed to make each forum's URL unique, you can remove the "phpBB2" from the on-page URLs generated by your scripts, and then use mod_rewrite to put "phpBB2" back into the path needed to call your scripts. As you surmised, the RewriteRules will have to be moved to the directory above phpBB2 in order for this to work.
So, if I move this to the parent directory, would I have to add a RewriteBase to the .htaccess or just insert the "phpBB2/" portions to the right-hand portions of the rewrite rule?
EDIT: I moved it, added "phpBB2/" to the right-hand portions, and get this as a result:
[test.example.net...]
The page redirects just fine, but the stylesheets and images are broken. Do I need to add additional rewrites to handle images and css stylesheets, or do I need to change the actual template/php files that generate the page?
[edited by: dari at 4:52 pm (utc) on Dec. 1, 2004]
thanks for all your help so far :)
more info on the error, here's the apache log entry for one such broken image:
a.b.c.d - - [01/Dec/2004:11:53:42 -0500] "GET /templates/nukedgallery/images/folder_hot.gif HTTP/1.1" 404 328 "http://test.example.net/forum5.html" "Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.7.5) Gecko/20041107 Firefox/1.0"
The attempt is being made at trying to pull it from /templates/blah/blah instead of /phpBB2/templates/blah/blah ... is there a rewrite rule I can use to fix this?
if anyone has any suggestions as to how to get the rewrite rule to include images and css, PLEASE help.
So you'll need to change the links on your php pages to access the images in the correct location. Since you've got two conflicting /images directories, mod_rewrite can't help here. An alternative would be to rename one of the /images directories and change the links that refer to it.
Jim
Sit back from this problem for a few days and think about ways to re-architect your site's directory structure. Among other things, you could move your forum to a subdomain, and thereby eleiminate all conflicts with the non-forum URLs.
Jim
RewriteRule ^/$ phpBB2/ [L]
to rewrite all URLs to the phpBB2 subdirectory, and thus pull the images and CSS sheets. This isn't working, though.
So, I tried:
RewriteRule ^.*$ /phpBB2/$1 [L]
No dice.
The site directory structure is:
/foo/bar ----> main site
/foo/bar/phpBB2 -----> forum site
Should the htaccess file with the phpBB2 specific rules still be in /foo/bar (ie, the CSS is in /foo/bar/phpBB2/templates/foo/ , so should I add a .haccess rule in /foo/bar to the effect of:
RewriteRule /templates/.*$ /phpBB2/templates/$1 [L]
?
EDIT: here is some more info:
in my /foo/bar, i've got an htaccess rule like this:
RewriteRule ^post(p¦t)([1-9][0-9]*).* phpBB2/viewtopic.php?$1=$2 [L]
which would redirect something like postp123.html to phpBB2/viewtopic.php?p=123
actually, now that i'm thinking about it, perhaps something like
RewriteRule ^post(p¦t)([1-9][0-9]*).* phpBB2/post$1$2.html [L]
and then in the phpBB2 directory have the rule like:
RewriteRule ^post(p¦t)([1-9][0-9]*).* viewtopic.php?$1=$2 [L]
it's two rewrites, but it's the best i can think of. if Jim or anyone else has a more efficient way, please let me know.
This isn't working, though.So, I tried:
RewriteRule ^.*$ /phpBB2/$1 [L]
No dice.
Please explain what you mean. "This isn't working" is not at all helpful to someone who is not looking over your shoulder. It is critical that you explain what does not happen as well as what does happen, otherwise, we can only guess. Give the limited amount of time that members can devote to reading and answering threads here, the most specific and detailed questions get answered, and the ones that don't contain sufficient information get lost.
The only guess I have is that a rule like that is likely to loop, because the output URL will match the input requirements, and on many servers, mod_rewrite in a directory context (.htaccess) is recursive.
To avoid a loop, you need to explicitly disallow it. Also, your back-reference $1 is undefined. Back-references are created by the use of parentheses around the parts of the pattern that you wish to back-reference:
RewriteCond %{REQUEST_URI} !^/phpBB2/
RewriteRule ^(.*)$ /phpBB2/$1 [L]
Jim
Alrighty, here's what happens with the following rewrites:
RewriteRule ^/$ phpBB2/ [L]
RewriteRule ^.*$ /phpBB2/$1 [L]
Both give me pages with the proper content, but broken images and no CSS applied (a viewing of the source shows that the CSS in the source is at "templates/foo/foo.css", when in reality, it's at "phpBB2/templates/foo/foo.css", but since the URL being viewed is "www.test.net/post123.html", it's not getting the proper path to the CSS and images.).
I've tried the rules in my "EDIT" of my previous post, but those yield the same, contextually correct, but graphically and stylistically broken, pages.