Home > Mobile >  htaccess file to hide subfolder
htaccess file to hide subfolder

Time:02-22

I'm struggling with the .htaccess file. I've wordpress installed in a subdirectory 'wordpress'. In the root folder if have the htaccess with the following content:

Order Allow,Deny
Allow from all
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond %{HTTP_HOST} ^(www\.)?example\.com$
RewriteRule !^wordpress/ /wordpress%{REQUEST_URI}  [L,R=301]
</IfModule>

Redirection is working, but how can I hide the subfolder 'wordpress'?

THX in advance

EDIT: Tried following content now but still not working:

root htaccess:

Order Allow,Deny
Allow from all
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond %{HTTP_HOST} ^(www\.)?example\.com
RewriteRule !^wordpress/ wordpress%{REQUEST_URI} [L]
</IfModule>

wordpress htaccess:

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
RewriteBase /wordpress/
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /wordpress/index.php [L]
</IfModule>

EDIT2: my whole root htaccess looks like this now:

Allow from all
RewriteEngine on
RewriteCond %{HTTP_HOST} ^(www\.)?example\.com
RewriteRule !^wordpress/ wordpress%{REQUEST_URI} [L]

If i type in www.example.com I am redirected to example/wordpress/home, example/wordpress/contact and so on...

I would like to hide the wordpress directory like example/home, example/contact and so on

CodePudding user response:

Redirection is working, but how can I hide the subfolder 'wordpress'?

You shouldn't be "redirecting". You should be internally rewriting the request instead. Remove the R flag.

For example:

RewriteCond %{HTTP_HOST} ^(www\.)?example\.com
RewriteRule !^wordpress/ wordpress%{REQUEST_URI}  [L]

The slash prefix on the susbtitution string is also not required.

This assumes you have the standard WP .htaccess file in the /wordpress subdirectory.

UPDATE: Also confirm you have removed the /wordpress subdirectory from the "Website Address" and "Site Address" in WordPress General settings.

  • Related