Forum Moderators: phranque
I have two folder structures on the same server
/current/website/accounts/
wherein the account folders are referenced and assigned web addresses using Apache Aliases
The second structure is
/newsite/
which has a CMS published site structure (ie apache will only be needed to point to this as DocumentRoot when the site is ready)
Unfortunately there are over 300 web accounts and migration to the new system will be slow. Therefore I need to run both file structures simultaneously.
My question is this. How can I pick out certain accounts from the Apache config and point them to the new file structure?
If I use redirect then that will work but it will also take out any sub addresses
eg www.site.com/section1 redirected will also redirect
www.site.com/section1/subaddress
If the sub address is another account that won't be updated for while then I'll be in trouble!
Has anyone any ideas as to a solution for this?
I thought maybe changing the Aliases to point to the new sections folder would be good enough but then that doesn't account for addresses with filenames
The new file structure published by the cms gives all pages a document name and one index file. Therefore if I forward any address with a filename on it eg contact.html this will be /newsite/filestructure/(index.html) on the new file structure.
Many thanks for taking a look, I'll keep you posted on progress in case someone else is following this and needs help too.
This will allow you to use regular expressions patterns to match any and all URL variations as needed, and rewrite those URL variations to the correct internal filepaths. Make use of mod_rewrite's RewriteCond directive when necessary to allow for multiple-condition cases and/or to simplify the logic.
Jim
Alias /depts/cc/halls /fs/web/old/folder/home
RewriteEngine on
RewriteRule ^/depts/cc/halls/[a-zA-Z0-9_.-]+/?(.*) http://www.example.co.uk/newaddress [R]
Now this sends all addresses with a file name to the new specified address. But unfortunately if the address is entered with just a slash
ie
http://www.example.co.uk/depts/cc/halls/
then it still shows the index.htm
any ideas how to forward the index aswell?
This solution also forwards any sub folders of this address. I only want this one folder to be redirected though. Is this where you would use "RewriteCond" ? I've read the apache docs on it but it doesn't seem clear to me.
Thanks again
Chris
[edited by: jdMorgan at 11:50 pm (utc) on June 4, 2009]
[edit reason] example.com or example.co.uk [/edit]
It should work in httpd.conf (or other config-level file), but it shouldn't work at all within a <Directory> container, nor within a .htaccess file...
But to answer your question, assuming you've put it in a config file:
RewriteRule ^/depts/cc/halls/([a-z0-9_.\-]+/?)?$ http://www.example.co..uk/newaddress [NC,R=301,L]
RewriteRule ^depts/cc/halls/([a-z0-9_.\-]+/?)?$ http://www.example.co..uk/newaddress [NC,R=301,L]
Jim
I have a main http.conf file which is referencing several virtual hosts. The vhost configs are kept in a different folder.
I'm using the rules above in the vhost for this domain and it is not within any <directory> or other tag. It's simply typed beneath the Alias.
I'm trying to forward all requests for the departmental pages because the new file naming scheme will be very different to the present one. ie if I append whatever.html to the rewritten address, then 'whatever.html' will not exist.
I'm trying to do a best effort at forwarding the old sections to the new sections and hence avoid hundred's of 404 errors. Maybe I'm going about it the wrong way..
I've tried
RewriteRule ^/depts/cc/halls/([a-z0-9_.\-]+/?)?$ http://www.example.co..uk/newaddress [NC,R=301,L]
and this now works great.
I was using [R] before as I wanted to notify search engines that the address was now changed to a new one. I see that [R=301] is the best way to let search engines know as it's a 'moved permanently' declaration; thanks for that.
Many thanks for the feedback, I'm new to this and it's much appreciated.
I think I now need to backwards engineer your rewriterule so I can get my head around how you did it !