Forum Moderators: phranque
I am not sure if following is possible but hope I can find some help here (if it can be done).
For my website i want to redirect pages located in different folders to the same subdomain.
www.site.com
www.site.com/folder1/pages
www.site.com/folder2/pages
www.site.com/folder3/pages
These pages i want to redirect to the same subdomainname.site.com
Thanks for the help
Option b is what I am searching for.
On the server I have:
domain / subdomain1/different folders and pages
Now I want that:
www.domain.com/subdomain1/anyfolder/anypage
wil point to subdomain1.domain.com/anyfolder/anypage
In my .htaccess:
RewriteEngine On
Options +FollowSymlinks
RewriteBase /RewriteCond %{HTTP_HOST} subdomain1.domain.com$
RewriteCond %{REQUEST_URI} !subdomain1/
RewriteRule ^(.*)$ subdomain1/$1
In the subdomain1 folder I included an index page
wildcard and mod_rewrite is on
-> when typing subdomain1.domain.com the index page is not found
-> when typing www.subdomain1.com the index page of subdomain1 is found
-> when surfing the website and clicking on a link that points to sudomain1 folder/pages it still shows the
www.domain.com/subdomain1/pages
How to make this work so all is pointing at subdomain1.domain.com/pages or when pages are in folder
subdomain1.domain.com/folder/pages
Thanks for the help and suggestions
You asked for a redirect, but your code is for a rewrite.
It is important to separate out what is namespace as a URL and what is namespace as a path on the server internals.
A redirect will contain a target hostname for the redirect, and [R=301,L] to flag the redirect.
What do you mean by "will point to"?
Does the URL the user sees change, or is content delivered from the other server location without revealing what that other location is?
URLs are defined by what is in the link that the user clicks on, so once you have the redirect/rewrite working, the links on the site should then also be updated.
I believe this will end up being the classical "Change links on pages to new URLs, rewrite new linked URLs to actual server filepaths, redirect only direct client requests for old URLs to new URLs"- type solution.
Jim
g1smd you are right when you tell me I use the code to rewrite. That is what I want. Sorry for that.
REQUEST_URI : htdocs/folder which has to be subdomain/here can be folders as well
I want that visitors see subdomain.domain.com/page (or file structure)
jdMorgan:
- subdomain.domain.com
- I link to the old structure www.domain.com/file/page (hope that a rewrite will do all)
- www.domain.com/foldersubdomainname/page
htdocs/folder i want to make subdomain/pages
htdocs/folder i want to make subdomain/folders in the folder/pages
Again thank you and hope my explanation i more clear now.
You will need to link to the new structure. The rewrite will NOT do what you want. A rewrite does not "change URLs". It connects a URL request clicked from a link, to a internal filepath on a server.
RewriteEngine on
Options +FollowSymLinks
#
# Externally redirect old subdomain-subdirectory URLs to new
# subdomain URLs if directly requested by a client
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /subdomain1/
RewriteRule ^subdomain1/(.*)$ http://subdomain1.example.com/$1 [R=301,L]
#
# Internally rewrite subdomain links to subdomain-subdirectory if not already
# done (this test is required to prevent an 'infinite' rewriting loop)
RewriteCond %{HTTP_HOST} ^subdomain1\.domain\.com
RewriteCond $1 !subdomain1/
RewriteRule (.*) subdomain1/$1 [L]
All changes between this code and your original code are entirely intentional.
Jim
[edited by: jdMorgan at 3:44 pm (utc) on Oct. 23, 2008]