Trying to redirect this format
archive/topic/t-59411_Nastase_RHIC_produces_black_holes.html
to this:
archive/index.php/t-59411.html
I can only find examples of what to do if they were querystrings.
thanks!!
Trying to redirect this format
archive/topic/t-59411_Nastase_RHIC_produces_black_holes.html
to this:
archive/index.php/t-59411.html
I can only find examples of what to do if they were querystrings.
thanks!!
fyi, I am looking for a redirect. the first url does not exist, it only exists in the second format
Redirect permanent /archive/topic/t-59411_Nastase_RHIC_produces_black_holes.html http://example.com/archive/index.php/t-59411.html
replace example.com with your domain
(see http://httpd.apache.org/docs/current/mod/mod_alias.html#redirect)
The number is dynamic though and the keywords are too, I’m going to try this:
RewriteRule ^archive/topic/t-([0-9]+)([[a-zA-Z0-9_]+).html$ archive/index.php/t-$1.html [R=301,L]
Looks good! I would add one slash just to be sure
RewriteRule ^archive/topic/t-([0-9]+)([[a-zA-Z0-9_]+).html$ [B][COLOR="#FF0000"]/[/COLOR][/B]archive/index.php/t-$1.html [R=301,L]
Just to be clear, but it might work fine without (my .htaccess is getting a bit rusty)
I got what I wanted mostly from this:
RewriteRule ^archive/topic/t-([0-9-]+)([[a-zA-Z0-9_]*).html$ archive/index.php/t-$1.html [R=301,L]
RewriteRule ^archive/topic/t-([0-9-]+)$ archive/index.php/t-$1.html [R=301,L]
RewriteRule ^archive/topic/([0-9-]+).html$ archive/index.php/t-$1.html [R=301,L]
RewriteRule ^archive/t-([0-9-]+)([[a-zA-Z0-9_]+).html$ archive/index.php/t-$1.html [R=301,L]
RewriteRule ^archive/t-([0-9]+)$ archive/index.php/t-$1.html [R=301,L]
I assume it’s not very efficent. Is there a more compact way to do this?
There is, but it’s highly unreadable and not any more efficient in terms of speed. I’d just stick with what you have now
I’ll give it a go for funsies.
RewriteRule ^archive/(?:topic/)?(?:t-)?(\d+)[^/]*\.html$ /archive/index.php/t-$1.html [R=301,L]
That misses two of the rules
RewriteRule ^archive/topic/t-([0-9-]+)([[a-zA-Z0-9_]*).html$ archive/index.php/t-$1.html [R=301,L]
[COLOR="#FF0000"]RewriteRule ^archive/topic/t-([0-9-]+)$ archive/index.php/t-$1.html [R=301,L][/COLOR]
RewriteRule ^archive/topic/([0-9-]+).html$ archive/index.php/t-$1.html [R=301,L]
RewriteRule ^archive/t-([0-9-]+)([[a-zA-Z0-9_]+).html$ archive/index.php/t-$1.html [R=301,L]
[COLOR="#FF0000"]RewriteRule ^archive/t-([0-9]+)$ archive/index.php/t-$1.html [R=301,L][/COLOR]
because they don’t end in .html, so that should be an optional group as well.
I never knew Apache 2 supported non-matching groups, good to know! :tup:
Oops. You’re right.
If the extension is optional, then we may be able to get away with leaving off the end of the pattern altogether.
RewriteRule ^archive/(?:topic/)?(?:t-)?(\d+) /archive/index.php/t-$1.html [R=301,L]