Forum Moderators: phranque
I currently have an .htaccess in a directory called /catalog. There is a subdirectory under that also called catalog ie: /catalog/catalog. All my old content has been moved from the subdirectory to /catalog
My rewrite rule contained in /catalog/.htaccess looks like this:
Options +SymlinksIfOwnerMatch
RewriteEngine on
RewriteBase /
RewriteRule ^/catalog(.*)$ http://www.example.com$1 [R=301,L]
However if the URL is www.example.com/catalog/catalog/stuff it doesn't rewrite it to just www.example.com/catalog/stuff which is what I'm shooting for.
I've tried some different permutations:
RewriteRule ^/catalog/catalog(.*)$ http://www.example.com/catalog$1 [R=301,L]
but the resultant URL still comes out http://www.example.com/catalog/catalog/stuff
Obviously I'm missing something here :)
Any guidance would be greatly appreciated. Many thanks.
The path to your current directory in this case is "/catalog/", so the RewriteRule won't match. Try:
RewriteRule [b]^cat[/b]alog(.*)$ http://www.example.com$1 [R=301,L]
Jim
Many thanks for your response. If I try:
RewriteRule ^catalog(.*)$ http://www.example.com$1 [R=301,L]
and use a URL like:
www.example.com/catalog/catalog/stuff
it gets rewritten as:
www.example.com/stuff and a resultant 404.
What I need is for:
www.example.com/catalog/catalog/stuff
to be rewritten and 301'ed as:
www.example.com/catalog/stuff
Thanks and sorry for the confusion.
Try:
RewriteRule ^catalog/catalog(.*)$ http://www.example.com/catalog$1 [R=301,L] Jim
Well, what you suggested sure makes sense to me:
RewriteRule ^catalog/catalog(.*)$ http://www.example.com/catalog$1 [R=301,L]
However using that as my RewriteRule nothing gets rewritten ie. using this URL:
http://www.example.com/catalog/catalog/stuff
still ends up in browser location as:
http://www.example.com/catalog/catalog/stuff
And I cleared cache, closed and opened 2 different browsers (IE6 and FF 1.5), ctrl F5 to force reload of page but still no joy :)
You may need to turn on
RewriteOptions inherit
(If inherit is not enabled in the server configuration, then subdirectories do not inherit the rewriterules and rewritemaps of their parent directories. Many if not most hosts turn it on by default to avoid this problem.)
Jim
No htaccess in /catalog/catalog
Yes the subdirectory still exists
Yes, I tried renaming it for testing purposes (/catalog/backup)
Still same results. Using the URL www.example.com/catalog/catalog/stuff results in the same URL with nothing being rewritten.
Many thanks Jim for taking the time to help me along here.
RewriteRule ^catalog/catalog(.*)$ http://www.example.com/catalog$1 [R=301,L]
must be located in example.com/.htaccess in order for the pattern to match your requested URL.
Is that the case? If so, I can't tell you why it won't work, unless you have httpd.conf access. If you do have access to the server config, then turn on detailed mod_rewrite logging to see where it's going wrong.
It's really frustrating when a very simple rule won't work on somebody's server...
Jim
First, much appreciated for you taking the time to help. I understand your frustration as I have tried the same scenario you have outlined on my own server and it works as advertised!
Unfortunately still not working on my friends setup - he is on shared hosting so no access to httpd.conf etc. and no real access to any forensic logs to see what is really going on.
For now we've just gone with a simple htaccess file in the /catalog/catalog directory with a simple 301 redirect up one directory - not as elegant as we would've liked but it handles the situation for now.
Again, many thanks Jim.