[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 250
  • Last Modified:

Changing URL (with PHP?)

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
mpaert
Asked:
mpaert
  • 4
  • 3
  • 2
1 Solution
 
Michael KnightCommented:
<?php
// Permanent redirection
header("HTTP/1.1 301 Moved Permanently");
header("Location: http://domain.com/joomla_dir");
exit();
?>
0
 
Michael KnightCommented:
that's safe and legit for search engine spiders as well.
0
 
mpaertAuthor Commented:
Thank you. will this hide the "subfolder" to the end user? - if not, how is it possible to hide it?
0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
mpaertAuthor Commented:
I've just tested it, and the subfolder does unfortunately show. The user should not know that there is a subfolder.
0
 
Michael KnightCommented:
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
 
Michael KnightCommented:
I mistyped:

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

should read

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

0
 
thomasd04Commented:
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
 
mpaertAuthor Commented:
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
 
thomasd04Commented:
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

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

  • 4
  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now