【问题标题】:htaccess - skip URL past root levelhtaccess - 跳过根级别的 URL
【发布时间】:2016-02-25 09:14:17
【问题描述】:

一直在尝试各种方法似乎无法弄清楚如何获得以下结果。我希望我的 url 将所有内容抓取到特定点,通过该文件链接并跳过其余的 url。但是,我的包含文件需要 URL 的其余部分,因此我希望它保留在 URL 中。

这是我想要的结果:

www.homepage.com/index/somepage,这将打开“index.php”并且什么都不做。

www.homepage.com/stuff/someotherpage,这将打开“stuff.php”并且什么都不做。

所以这很简单,但我不知道在使用多个页面时如何实现这一点。我可以让它每次都简单地重定向到 index.php,但这不是我想要的结果。

目前的进展:

<IfModule mod_rewrite.c>
RewriteEngine On

# Force everything through the index.php file
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
</IfModule>

【问题讨论】:

    标签: .htaccess directory root forward


    【解决方案1】:

    你可以这样开始,捕获URL的第一部分并重定向到这个页面.php

    如果您有更复杂的页面名称,您可以更改 ([a-z]+)。

    <IfModule mod_rewrite.c>
    RewriteEngine On
    
    # Force everything through the index.php file
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteRule ^([a-z]+)/(.*) $1.php?param_url=$2 [L]
    </IfModule>
    

    【讨论】:

    • 我可以把它连接起来,让它总是使用网址的第一部分而第二部分被忽略吗?
    • 嗯,这正是它的作用:)
    猜你喜欢
    • 2016-10-16
    • 2015-02-27
    • 2013-09-30
    • 1970-01-01
    • 2016-01-13
    • 2018-01-24
    • 2015-04-15
    • 1970-01-01
    • 2011-05-01
    相关资源
    最近更新 更多