Solved

Changing URL (with PHP?)

Posted on 2011-02-18
9
244 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:Michael Knight
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:Michael Knight
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
Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

 

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
 
LVL 9

Expert Comment

by:Michael Knight
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:Michael Knight
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

Webinar: Aligning, Automating, Winning

Join Dan Russo, Senior Manager of Operations Intelligence, for an in-depth discussion on how Dealertrack, leading provider of integrated digital solutions for the automotive industry, transformed their DevOps processes to increase collaboration and move with greater velocity.

Question has a verified solution.

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

Suggested Solutions

This article discusses how to create an extensible mechanism for linked drop downs.
There’s a good reason for why it’s called a homepage – it closely resembles that of a physical house and the only real difference is that it’s online. Your website’s homepage is where people come to visit you. It’s the family room of your website wh…
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
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…

809 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