Forum Moderators: phranque
http://www.mysite.com/forum/subform-name/48975-trichopilia-tortilis-leaf-tips.html
http://www.mysite.com/forum/showthread.php?t=48975 http://www.mysite.com/forum/content/178-raft-cork-deteriorated-replace.html http://www.mysite.com/forum/content.php?r=178-Raft-cork-deteriorated-to-replace
I've researched and read as much as I can so that I could ask the precise questions I needed help with from people who understand what I am attempting. I've supplied both of the two URL types that I need help with (forum URL and CMS URL), and what the final result should be after the 301 redirect.Well, that's certainly a start, and is a heck of a lot more than some folks have done by way of preparation. But unfortunately, what I meant was, “What attempts at a RewriteRule have you formulated? Which parts work as intended, and which parts don’t?” There exist forums that will simply write your code for you--generally at a cost of several snarky preliminary comments pointing out that the same question was asked and answered back in 2015, with a link that nobody but a Forums regular would know how to find. But I digress.
http://www.example.com/forum/content/178-raft-cork-deteriorated-replace.htmlThis is where it really seems as if everything could be done with an internal rewrite, letting you hold on to your established URLs. You're moving from
...
http://www.example.com/forum/content.php?r=178-Raft-cork-deteriorated-to-replace
/forum/content/blahblah.html
to
/forum/content.php?r=blahblah
(I did see a casing issue between “raft” and “Raft”, but php should be able to deal with that.) Human users don't need to see the new URL; only your forums software does. /forum/subforumname/stringofnumbers-moreblahblah.html
/forum/showthread.php?t=stringofnumbers
while discarding the subforumname and the part after the numbers. Is that all that's happening? forum-name/threadname-threadid.html RewriteEngine on RewriteRule [^/]+/([0-9]+)-[^/]+\.html http://www.mysite.com/forums/showthread.php?t=$1 [L,R=301] RewriteEngine on RewriteRuleI hope this was just an artifact of posting. You say “RewriteEngine on” just once--logically before all RewriteRules, but the server doesn’t care--on a line by itself. For your own sanity, leave a blank line between each ruleset, though again the server doesn’t care. (That is, it's not like robots.txt where a blank line has syntactic meaning.)
I read today that I can use 'NC' to keep the capitalization of words from making a difference, but I'm not certain where it needs to go.The NC flag applies only to patterns--either the left-hand side in the body of the rule, or to any individual RewriteCond. Unfortunately there is no mod_rewrite flag that means “match the original casing” or “capitalize the first word” or what-have-you. This may or may not turn out to be a problem, depending on the specific circumstances. It is even possible that the Forums software itself includes a case-leveling function, so casing of the URL doesn't matter.
And, the "L" before the redirect=301 ends that particular rule, so I'm guessing that it would only go in the final bit of code once I learn how to redirect the CMS urls.Think of [R] and [L] as an inseparable couple; normally anything with an R flag (or R=301) also takes the L flag. Most of the time, any given request will only match one pattern, so you need to apply the L right away. Otherwise the server will keep checking all the other RewriteRules, which is just a waste of server resources.
externally redirect requests for the internal form of the url to the canonical external urlsDo these requests even exist? I got the impression there were two different URL formats, and the ones with the query string have never been visible as external URLs, so nobody is requesting them. (I hope so, because it makes things a lots easier.)
RewriteRule ^(request-matching-old-url-pattern)$ /specialpage.php?oldurl=$1 [L]
In spite of the [L] flag, this rule would be located at the beginning of the RewriteRules that have the [R] flag. If this turns out to be necessary we can hammer out more details, but with luck it won't be needed. (This format is a little worrying because your server access logs will show a 200 response for all requests, and you have to take it on faith that the redirects were all issued, unless you have your php page create a supplementary log of its own.)
I'm still struggling with the CMS redirect code. (if in fact the Forum redirect code I supplied in MSG4972356 above is actually correct and will do what I'm hoping it will do. Any thoughts on the CMS code?
RewriteRule [^/]+/([0-9]+)-[^/]+\.html http://www.mysite.com/forums/showthread.php?t=$1 [L,R=301] http://www.mysite.com/forum/subform-name/48975-trichopilia-tortilis-leaf-tips.html
Here is what I need to redirect to when I remove VBSEO (this is the url when I disable the product)http://www.mysite.com/forum/showthread.php?t=48975
RewriteRule /([0-9]+)-[^/]+\.html$ /forums/showthread.php?t=$1 [L]
1 - there is an inconsistency between your problem description (/forum/) and your code sample (/forums/).
i'll assume "forum" is correct.
2 - the regular expression in your code sample won't match the requested path because there are 2 slashes before the numeric string.
i would start the pattern with the slash before the captured numeric string and add an end anchor.
i.e. /([0-9]+)-[^/]+\.html$
3 - if you want to retain the old urls, why not use an internal rewrite instead of an external redirect?
RewriteRule /([0-9]+)-[^/]+\.html$ /forums/showthread.php?t=$1 [L] http://www.mysite.com/forum/content/178-raft-cork-deteriorated-replace.html http://www.mysite.com/forum/content.php?r=178-Raft-cork-deteriorated-to-replace RewriteRule /([0-9]+)-[^/]+\.html$ /forums/content.php?t=$1 [L] So, here is and example of the forum URL in the CMS now using VBSEO
http://www.mysite.com/forum/content/178-raft-cork-deteriorated-replace.html
Here is what I need to redirect (or rewrite) to when I remove VBSEO (this is the url when I disable the product)
http://www.mysite.com/forum/content.php?r=178-Raft-cork-deteriorated-to-replace
Based on what you did with the forum URL rewrite, would the below then work for the CMS? They are the same with the exception of the php file name and the title text. I feel like there is something missing since I'm not sure what to put in to get the text that appears after the content ID number (IE ".Raft-cork-deteriorated-to-replace). Is that covered when the t=$1 calls for the thread id? Does it need another call? I'm not sure if I'am even asking the question correctly. I hope you can understand what I mean.RewriteRule /([0-9]+)-[^/]+\.html$ /forums/content.php?t=$1 [L]
RewriteRule /([0-9]+-[^/]+)\.html$ /forum/content.php?r=$1 [L] RewriteRule /This bit makes me uneasy. A pattern with leading / slash will only match* if there is something before the slash. In this case I guess you’re aiming for the element /forum/ but as written there could be anything-and-everything. It is better to start with an opening anchor and then the exact text-to-match. This is partly to avoid Unintended Consequences** but more to save the server work:
RewriteRule ^forum/blahblah
where “blahblah” is the part you and phranque have been discussing. =phranque ...is it only and always the first alphabetic character that is upper case?
=phranque and /forum/, not /forums/.
=lucy24The NC flag applies only to patterns--either the left-hand side in the body of the rule, or to any individual RewriteCond. Unfortunately there is no mod_rewrite flag that means “match the original casing” or “capitalize the first word” or what-have-you. This may or may not turn out to be a problem, depending on the specific circumstances. It is even possible that the Forums software itself includes a case-leveling function, so casing of the URL doesn't matter.
NC|nocase
Use of the [NC] flag causes the RewriteRule to be matched in a case-insensitive manner. That is, it doesn't care whether letters appear as upper-case or lower-case in the matched URI.
In the example below, any request for an image file will be proxied to your dedicated image server. The match is case-insensitive, so that .jpg and .JPG files are both acceptable, for example.RewriteRule "(.*\.(jpg|gif|png))$" "http://images.example.com$1" [P,NC]
=phranque you would need to capture the entire alphanumeric string.
... use the "r" parameter in the target.
more like:
RewriteRule /([0-9]+-[^/]+)\.html$ /forum/content.php?r=$1 [L]
RewriteRule /([0-9]+-[^/]+)\.html$ /forum/content.php?r=$1 [NC,L] RewriteRule / vrs the RewriteRule ^ I'm at a loss. The forum folder is in the root of the site, so nothing should come before it in sequence. I do not have, for example: something.example.com/forum/123.html (Is that what you mean?) I'm still not sure if I understand this completely since on the Apache RewriteRule Flags page on the net it says this about NC:
Will this only work for images as in the example or is it more broad as their definition implies? I wonder if adding in the [NC] might solve the case issue.
I'm hoping the forum software will simply take care of the case issue, but I've been unable to find out if that is true or not.
As for the discussion about the...
RewriteRule ^forum/[^/]+/([0-9]+-[^/]+)\.html$ /forum/content.php?r=$1 [L] The forum folder is in the root of the site, so nothing should come before it in sequence. I do not have, for example: something.example.com/forum/123.html (Is that what you mean?)No, the hostname isn't part of the string-to-match. But the issue isn't where the /forum/ directory is located; it's where the RewriteRule is located.