2

I have a web app project located in a directory called issues with several sub directories.

The folder structure is as follows:

-issues
    -applications
    -cli
    -library
    -public
        -css
        -js
        index.php

If you point the url to the issue folder nothing happens. To load the website the URL needs to point to issues/public and then the site runs from there.

Is there a way to have the url point to just the issues directory but load the files as if it was in the issues/public directory?

Everything is linked in such a way in the application that it would be impossible to move the contents of the public folder to the issues folder.

I was looking at htaccess redirects and have so far managed to redirect issues to issues/public but this isn't ideal.

I did that using the following:

RewriteRule ^issues\/?$ "/issues\/public" [R=302,L]
1
  • Bit of a side issue, but in internally rewriting to a subfolder, any relative client-side paths might break. (?)
    – MrWhite
    Mar 12, 2015 at 14:12

2 Answers 2

3

Rewrites are what you're looking for as long as you don't redirect (the R flag):

# placed under root, ie /.htaccess
<IfModule mod_rewrite.c>
   RewriteEngine on
   # to prevent infinite redirection and 500 error:
   RewriteCond %{REQUEST_URI} !^/issues/public 
   RewriteRule ^issues(/?$|/.*$) /issues/public$1 [L]
</IfModule>

Aliases can act—sort of—similarly, but they're not the right tool for the job. They are more comparable to filesystem symlinks than URL-rewriting. Read more from a Stack Overflow answer.

2
  • Will probably need to remove the line-end comment on the RewriteCond directive as this is likely to break. (Line-end comments aren't actually supported on Apache. Although they sometimes "work" when there is no ambiguity.) Might also need to make the capturing subpattern on the RewriteRule optional if the OP wants to match /issues.
    – MrWhite
    Mar 12, 2015 at 14:06
  • @w3d true. Ironically the line meant to fix a 500 error threw one itself… Missing trailing slashes are usually automatically handled by Apache, if that was what you meant, but I've modified the sub pattern to handle "/issues" request as well. Mar 12, 2015 at 14:40
1

With a redirect you'll always be redirecting the user to another location, thus changing the url. Therefore you would probably want to use mod_alias instead of mod_rewrite.

Alias /issues /absolute/filesystem/path/to/issues/public

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.