skip to Main Content

I’m developing a website and trying to obtain:

http://localhost/dir1/dir2/index.html#home

to become:

http://localhost/index.html#home

Tried:

RewriteEngine On
RewriteRule ^/?$ /dir1/dir2/

but no luck, it redirects to http://localhost/dir1/!

My index.html file is under /var/www/html/dir1/dir2 folder, as you imagine see from the URL.

Any help please?

Thanks

I’m developing a website and trying to obtain:

http://localhost/dir1/dir2/index.html#home

to become:

http://localhost/index.html#home

Tried:

RewriteEngine On
RewriteRule ^/?$ /dir1/dir2/

but no luck, it redirects to http://localhost/dir1/!

My index.html file is under /var/www/html/dir1/dir2 folder, as you imagine see from the URL.

Any help please?

Thanks

*Edit**:

The .htaccess is placed in the root folder, so in dir1‘s parent.

2

Answers


  1. to rewrite Rewrite
    http://localhost/dir1/dir2/index.html#home
    to
    http://localhost/index.html#home

    use

    RewriteEngine On
    RewriteRule   dir1/dir2/ ""
    
    Login or Signup to reply.
  2. Try this one:

    RewriteEngine On
    RewriteBase /
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    
    RewriteRule ^(.*)$ /dir/dir/$ [NC,L]
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search