【问题标题】:Remove some parts of URl with .htaccess?使用 .htaccess 删除 URl 的某些部分?
【发布时间】:2019-01-18 22:28:33
【问题描述】:

我正在开发一个网站并试图获得:

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

变成:

http://localhost/index.html#home

试过了:

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

但运气不好,它重定向到http://localhost/dir1/

我的index.html 文件位于/var/www/html/dir1/dir2 文件夹下,正如您想象的从URL 中看到的那样。

有什么帮助吗?

谢谢

我正在开发一个网站并试图获得:

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

变成:

http://localhost/index.html#home

试过了:

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

但运气不好,它重定向到http://localhost/dir1/

我的 index.html 文件位于 /var/www/html/dir1/dir2 文件夹下,正如您想象的从 URL 中看到的那样。

有什么帮助吗?

谢谢

*编辑**:

.htaccess 放置在根文件夹中,因此在dir1 的父级中。

【问题讨论】:

    标签: apache .htaccess


    【解决方案1】:

    重写重写 http://localhost/dir1/dir2/index.html#homehttp://localhost/index.html#home

    使用

    RewriteEngine On
    RewriteRule   dir1/dir2/ ""
    

    【讨论】:

    • 谢谢,但它对我不起作用。我的网址没有任何变化。我尝试直接调用http://localhost/dir1/dir2/index.html#home,并添加一个执行header('Location: ./dir2/index.html');/dir1/index.php
    【解决方案2】:

    试试这个:

    RewriteEngine On
    RewriteBase /
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    
    RewriteRule ^(.*)$ /dir/dir/$ [NC,L]
    

    【讨论】:

    • 谢谢,但它对我不起作用。我的网址没有任何变化。我尝试直接调用http://localhost/dir1/dir2/index.html#home 并添加一个执行header('Location: ./dir2/index.html');/dir1/index.php
    猜你喜欢
    • 1970-01-01
    • 2018-10-04
    • 2019-06-18
    • 2020-12-21
    • 1970-01-01
    • 1970-01-01
    • 2012-02-26
    • 2014-06-26
    相关资源
    最近更新 更多