Solved

Changing URL (with PHP?)

Posted on 2011-02-18
9
241 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
Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

 
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

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
Error viewing ASP page 12 82
PHP connection to remote AWS MySQL RDS 4 36
php documentation 4 19
update field on focusout 15 20
Envision that you are chipping away at another e-business site with a team of pundit developers and designers. Everything seems, by all accounts, to be going easily.
"In order to have an organized way for empathy mapping, we rely on a psychological model and trying to model it in a simple way, so we will split the board to three section for each persona and a scenario and try to see what those personas would Do,…
The viewer will learn how to count occurrences of each item in an array.
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

707 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

11 Experts available now in Live!

Get 1:1 Help Now