Home > Software engineering >  Use alias in .htaccess
Use alias in .htaccess

Time:01-05

I am translating this with the google translator so if something is misspelled then sorry It turns out that I have a phaser game that is compiled with webpack to a dist folder, but the entire project itself is inside apache, that is, it is already public, so to speak, so I would like to be able to configure with a .htaccess that all requests to the game for example http://localhost/game/index.html will show me the document of game/dist/index.html but without redirecting me.

I know that I can do this with an Alias in the httpd.conf but I would like to do it with an .htaccess inside the game folder.

Thank you.

CodePudding user response:

Try the following in /game/.htaccess using mod_rewrite to internally rewrite all requests to a dist subdirectory:

RewriteEngine On

RewriteCond %{REQUEST_URI} ^/[^/] /(.*)
RewriteRule !dist/ dist/%1 [L]

This basically rewrites all requests that are not already for the dist subdirectory to the dist subdirectory.

%1 is a backreference to the captured group in the preceding CondPattern. ie. the URL-path that follows /game/.

  •  Tags:  
  • Related