Forum Moderators: phranque

Message Too Old, No Replies

Moving subdirectories - Having problems with RewriteRule

Moving subdirectories - Having problems with RewriteRule

         

classifieds

1:52 pm on Jan 4, 2015 (gmt 0)

10+ Year Member



I've read through 50 posts on this topic, found dozens of examples, read the apache documentation and I cannot figure out why my RewriteRule is not being executed.

It should be very simple. . .

I'm reorganizing my subdirectories moving from "/Wakulla_News/Local_News/Wakulla_Outdoors/" to "/Wakulla_Outdoors/"

The rule is:
RewriteRule ^Wakulla_News/Local_News/Wakulla_Outdoors/(.*)$ http://www.example.com/Wakulla_Outdoors/$1 [R=301,L]


The entire .htaccess file is below.

Any assistance would be appreciated.

Regards,

-jay

RewriteEngine On
RewriteBase /
DirectoryIndex index.php index.html
IndexIgnore *
Options -Indexes

###### Add trailing slash (optional) ######
RewriteCond %{REQUEST_URI} ^/[^\.]+[^/]$
RewriteRule ^(.*)$ $1/ [R=301,L]

###### external redirect from /index.php/foo to /foo ######
RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s/+index\.php(/.+)?[\s\?] [NC]
RewriteRule ^ %1 [L,R=301]

##### Joomla! core SEF Section -- BEGIN
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
RewriteCond %{REQUEST_URI} !^/index\.php
RewriteCond %{REQUEST_URI} /component/|(/[^.]*|\.(php|html?|feed|pdf|raw|ini|zip|json|file|vcf))$ [NC]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule .* index.php [L]
##### Joomla! core SEF Section -- END

RewriteRule ^Wakulla_News/Local_News/Wakulla_Outdoors/(.*)$ http://www.example.com/Wakulla_Outdoors/$1 [R=301,L]



edit: Changed ****.com to Example.com

lammert

4:27 pm on Jan 4, 2015 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Have you tried moving your rule up in the .htaccess file? One of the other rules might trigger before yours.

not2easy

6:15 pm on Jan 4, 2015 (gmt 0)

WebmasterWorld Administrator 10+ Year Member Top Contributors Of The Month



Since the
^
(starts with) anchor does not include the domain stuff, you can leave that off the target as the rule is for the part between
^
and
$
(end). I would replace
(.*)
with
?
so the first part of the rule is:
^Wakulla_News/Local_News/Wakulla_Outdoors/?$

and the second part without the domain would be:
/Wakulla_Outdoors/$1 [R=301,L]


I won't comment on the number of things you want Indexes to do in the first few lines of the .htaccess file and just assume you know what that is about. I know nothing of Joomla, but having tasted it once a long time ago, I know it is weirder than WP.

Note: You can go ahead and try these, but Lucy will be in later to set us all straight.

classifieds

8:40 pm on Jan 4, 2015 (gmt 0)

10+ Year Member



@lammert - I've moved it at each attempt hoping it was a precedence issue.

@not2easy - Made your suggestion and no change... Sssiiiggghhh. . .
RewriteRule ^Wakulla_News/Local_News/Wakulla_Outdoors/?$ http://wwww.example.com/Wakulla_Outdoors/$1 [R=301,L]

not2easy

9:05 pm on Jan 4, 2015 (gmt 0)

WebmasterWorld Administrator 10+ Year Member Top Contributors Of The Month



No, that's not quite what I said. What I said was:
and the second part without the domain would be:
/Wakulla_Outdoors/$1 [R=301,L]

Remove the http stuff and domain, you aren't rewriting that part.

lucy24

9:27 pm on Jan 4, 2015 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Remove the http stuff and domain, you aren't rewriting that part.

He's not rewriting at all, he's redirecting. A redirect target should always include full protocol-plus-domain. (A rewrite target mustn't, or it changes into a 302.)

classifieds, your RewriteRules should be arranged from "most specific" to "most general" so the new rule should definitely go before all other redirects (rules with [R] flag).

Have you emptied your browser cache or, better, tried the request with a browser you don't normally use? In addition to pages, redirect responses themselves can be cached. So your browser doesn't automatically know that the redirect target has changed.

The rule is:
RewriteRule ^Wakulla_News/Local_News/Wakulla_Outdoors/(.*)$ http://www.example.com/Wakulla_Outdoors/$1 [R=301,L]

On the face of it, this is absolutely correct. But are you dealing with real, physical files? I can't help but notice the reference to Joomla further along.

I cannot figure out why my RewriteRule is not being executed

Double-check with an extension such as LiveHeaders to verify that nothing extra is happening. If you're on shared hosting, you can't check the RewriteLog, so that line of inquiry is out.

classifieds

2:46 am on Jan 5, 2015 (gmt 0)

10+ Year Member



will run though these in the am. thks!

classifieds

11:21 am on Jan 5, 2015 (gmt 0)

10+ Year Member



It's working now.

RewriteRule ^Wakulla_News/Local_News/Wakulla_Outdoors/(.*)$ http://www.example.com/Wakulla_Outdoors/$1 [R=301,L]


Moved the rule to to the top, cleared browser cache, turned off server-side app-caching, used an incognito browser (chrome & firefox).

Not sure what resolved it but thank you all for the attention!

-jay

lammert

11:44 am on Jan 5, 2015 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Thank you for reporting back. Good to hear that it is working now.