Forum Moderators: phranque
RewriteCond %{REQUEST_URI} /news/gallery/(.*)$
RewriteRule ^(.*) https://www.example.com/gallery/%1 [L,R=301] https://www.example.com/news/gallery/benjaminson_jim_1932.htm https://www.example.com/gallery/ ^(.*)... (.*)... (.*)$ ^(.*)$ The new url is https://www.example.com/gallery/benjaminson_jim_1932.htmhttps://www.example.com/gallery/benjaminson_jim_1932.htm [edited by: not2easy at 4:13 pm (utc) on Jul 8, 2022]
[edit reason] Please see TOS [webmasterworld.com] [/edit]
it isn't necessarily a good idea to use an htaccess checking tool to assess a rule which is to go in config.
I think we noted in the other thread that it isn't necessarily a good idea to use an htaccess checking tool to assess a rule which is to go in config.I understand that. Right now, all the rules are in a .htaccess file because that's where the hosting support people put them. I would prefer to have them in the conf file but right now, I'm simply trying to get them working.
Try the rule-only version and see if that works as intended. And then we can figure out what on earth your server has against %1 capturing from the RewriteCond. You don't have any supplementary Conditions that you've omitted for posting purposes, do you?Yes, I have other rules and conditions in the .htaccess file, but it was my understanding that a RewriteCond only applies to the RewriteRule that immediately follows it as long as you use the L flag. Was my understanding wrong? I commented out the RewriteCond and tested the rule that @robzilla suggested. So we're clearly on the same page, I'm going to post the entire contents of the .htaccess file.
# cat /var/www/html/.htaccess
RewriteEngine On
RewriteOptions Inherit
RewriteRule ^links/ /links.html [L,R=301]
RewriteCond %{QUERY_STRING} ubb=get_profile;u=(\d+)\b
RewriteRule ^bboard/.*$ https://www.example.com/ubbthreads/ubbthreads.php?ubb=showprofile&User=%1 [L,R=301]
RewriteCond %{QUERY_STRING} page=get_profile;u=(\d+)\b
RewriteRule ^bboard/.*$ https://www.example.com/ubbthreads/ubbthreads.php?ubb=showprofile&User=%1 [L,R=301]
RewriteCond %{QUERY_STRING} page=editprofile;u=(\d+)\b
RewriteRule ^bboard/.*$ https://www.example.com/ubbthreads/ubbthreads.php?ubb=showprofile&User=%1 [L,R=301]
RewriteCond %{REQUEST_URI} /bboard/cgi-bin/ultimatebb.cgi
RewriteRule (.*)$ https://www.example.com//ubbthreads/ubbthreads.php [L,R=301]
RewriteCond %{QUERY_STRING} page=getprofile;u=(\d+)\b
RewriteRule (.*)$ https://www.example.com//ubbthreads/ubbthreads.php?ubb=showprofile&User=%1 [L,R=301]
#RewriteCond %{REQUEST_URI} /news/gallery/(.*)$
RewriteRule ^news/gallery/(.*)$ https://www.example.com/gallery/%1 [L,R=301]All of these rules are working as intended, except the last one, which is what we are discussing in this thread. Do you have other rules in place? Is this a straight redirect from /news/gallery/benjaminson_jim_1932.htm to /gallery/ or is there a chain? You can use your browser's Developer Tools to check, or an online tool such as httpstatus.io.Thanks for the tips on Developer Tools and httpstatus.io.
You have the same discussion going on over here: [webmasterworld.com...] and you have received answers but seem to be ignoring the good advice you're getting.It was my opinion that this was a new topic separate from the previous thread. I felt if I posted this question in that thread, people would say I was off topic for that thread. I apologize. I'm still learning the ropes here.
[edited by: not2easy at 8:13 pm (utc) on Jul 8, 2022]
[edit reason] Please Use example.com For Domain Names in Apache Web Server forum [/edit]
my understanding that a RewriteCond only applies to the RewriteRule that immediately follows it as long as you use the L flagA RewriteCond always belongs to its adjoining rule; the [L] flag has no effect on this. So the question was whether you might possibly have something like--putting this as generically as possible--
RewriteRule ^news/gallery/(.*)$ https://www.example.com/gallery/%1 [L,R=301]Oh, yikes, remember that if you’re capturing from the Rule rather than from the Condition, you have to say $1 rather than %1. (I suppose it's too much to hope that the solution turned out to be that simple...)
I just noticed that the rule @robzilla posted used $1 for the reference instead of %1. So, I changed it and tested it again. It still took me to the index page. (I was so hoping that was all it was.) It has to be something subtle that I'm missing.
because the good folks in this forum have pointed out repeatedly that .htaccess files should not be used whenever possible.
# cat /var/www/html/.htaccess
RewriteEngine On
RewriteOptions Inherit
[edited by: robzilla at 8:24 pm (utc) on Jul 8, 2022]
RewriteOptions Inherit is pointless here, assuming that /var/www/html/ is the root folder of your website. There are no parent directories to inherit .htaccess rules from.
Is there by any chance a separate .htaccess file in /news/ or /news/gallery/? (Or a rule in your Apache conf that affects any of those paths)
My browser cache was getting in the way.Another option is to temporarily express all rules as 302 rather than 301, so the browser doesn't try to recycle whatever redirect it received five minutes ago. But, yes, this is the point at which you pore over the browser's keyboard shortcuts and learn the command for Force Reload.