?
Solved

Changing URL (with PHP?)

Posted on 2011-02-18
9
Medium Priority
?
247 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
The Orion Papers

Are you interested in becoming an AWS Certified Solutions Architect?

Discover a new interactive way of training for the exam.

 

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
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
 
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 2000 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

Get proactive database performance tuning online

At Percona’s web store you can order full Percona Database Performance Audit in minutes. Find out the health of your database, and how to improve it. Pay online with a credit card. Improve your database performance now!

Question has a verified solution.

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

Originally, this post was published on Monitis Blog, you can check it here . It goes without saying that technology has transformed society and the very nature of how we live, work, and communicate in ways that would’ve been incomprehensible 5 ye…
Ready to get certified? Check out some courses that help you prepare for third-party exams.
The viewer will learn how to count occurrences of each item in an array.
Learn how to create flexible layouts using relative units in CSS.  New relative units added in CSS3 include vw(viewports width), vh(viewports height), vmin(minimum of viewports height and width), and vmax (maximum of viewports height and width).
Suggested Courses

764 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