Solved

Changing URL (with PHP?)

Posted on 2011-02-18
9
242 Views
Last Modified: 2012-08-13
Hi,

For practical and administrational reasons I want to install a joomla installation to a subdirectory (domain.com/directory/joomla_dir).

My question is if there is any way for users, who visit "domain.com" to user the joomla data (in "joomla_dir"), whilst the browsers formats the URL for them as "domain.com/joomla_dir"?

Thanks

MP
0
Comment
Question by:mpaert
  • 4
  • 3
  • 2
9 Comments
 
LVL 9

Expert Comment

by:michaelaknight
ID: 34929591
<?php
// Permanent redirection
header("HTTP/1.1 301 Moved Permanently");
header("Location: http://domain.com/joomla_dir");
exit();
?>
0
 
LVL 9

Expert Comment

by:michaelaknight
ID: 34929597
that's safe and legit for search engine spiders as well.
0
 

Author Comment

by:mpaert
ID: 34929664
Thank you. will this hide the "subfolder" to the end user? - if not, how is it possible to hide it?
0
 

Author Comment

by:mpaert
ID: 34929684
I've just tested it, and the subfolder does unfortunately show. The user should not know that there is a subfolder.
0
3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

 
LVL 9

Expert Comment

by:michaelaknight
ID: 34929782
The user will see the full URL of whatever URL you redirect them to.

So redirecting to http://domain.com/joomla_dir   they will see http://domain.com/joomla_dir/foo.php
redirecting to http://domain.com/joomla_dir they will see http://domain.com/joomla_dir/foo.php

But, your website structure has to align with that.

If you really want that extra /joomla_dir then You'd change the default directory to one level below /joomla_dir (/directory/ in your example) use that as the default directory and put the above 301 redirect.  So what you're doing is changing the default virtual directory, putting an index.php in there and redirecting to higher level directory. the lower you go the more /directory/directory1/directory2/ You're going to have to add to the redirect. Follow?

Is this shared hosting or is this your machine?

If the Joomla Install is going to be the only portion of the website, then why do you want to redirect/hide at all?

Why not just change the default directory in Apache? So you'd get http://domain.com/foo.php

0
 
LVL 9

Expert Comment

by:michaelaknight
ID: 34929792
0
 
LVL 3

Expert Comment

by:thomasd04
ID: 34929992
Hi mpaert. I believe you can use the Apache Mod_Rewrite module in your .htaccess file to accomplish what you want.

RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ directory/$1 [QSA,L]

Open in new window

Good luck!
0
 

Author Comment

by:mpaert
ID: 34934455
Hi Thomasd04

If this solution make any subdirectories appear as a top level directory file/site, then this is great, however, could you explain a little more on how to implement it - directory is self explanatory, but "request_filename", would this be the "index.php" file in the "directory"?

Thanks
0
 
LVL 3

Accepted Solution

by:
thomasd04 earned 500 total points
ID: 34935382
You first need to have a .htaccess file in the root of your domain. On the file you should include code similar to what I had provided above. Here are some explanations of the expressions:

* If the request is for a real directory (one that exists on the server), index.php isn't served.
RewriteCond %{REQUEST_FILENAME} !-d

Open in new window

* If the request is for a file that exists already on the server, index.php isn't served.
RewriteCond %{REQUEST_FILENAME} !-f

Open in new window

* This redirects the URL from domain.com/ to domain.com/directory/
RewriteRule ^(.*)$ directory/$1 [QSA,L]

Open in new window

* This is another way to the document root using the RedirectMatch directive.
RedirectMatch ^/$ http://yourdomain.com/directory/

Open in new window


Since I've never actually done this on any of my websites I'm not sure of the exact code. This may be a little unclear until you play with it a bit. You can find more examples and info here:
http://httpd.apache.org/docs/2.0/misc/rewriteguide.html

I hope this helps!

0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Why do we like using grid based layouts in website design? Let's look at the live examples of websites and compare them to grid based WordPress themes.
Password hashing is better than message digests or encryption, and you should be using it instead of message digests or encryption.  Find out why and how in this article, which supplements the original article on PHP Client Registration, Login, Logo…
Any person in technology especially those working for big companies should at least know about the basics of web accessibility. Believe it or not there are even laws in place that require businesses to provide such means for the disabled and aging p…
Video by: Mark
This lesson goes over how to construct ordered and unordered lists and how to create hyperlinks.

863 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

27 Experts available now in Live!

Get 1:1 Help Now