【问题标题】:rewrite rule for .htaccess file.htaccess 文件的重写规则
【发布时间】:2013-01-30 09:03:57
【问题描述】:

我需要在我的网站中编写重定向规则。我正在使用 codeigniter。所以它将对所有页面使用 index.php。 所以我使用的第一条规则是

RewriteRule ^(.*)$ /index.php/$1 [L].

现在我想添加一些如下内容。

我的要求第一:

输入 - example.com/index.php/search/query

要重定向的网址 - example.com/search?q=query

还有,

输入 - example.com/index.php/search/query&c=abc&s=xyz&p=1

要重定向的网址 - example.com/search?q=query&c=abc&s=xyz&p=1

就是这样。

任何人都可以破解这个密码吗?请...

提前致谢。

已编辑:告诉一些参考网站了解更多关于编写 .htaccess 文件的规则和条件语法。

【问题讨论】:

    标签: php .htaccess


    【解决方案1】:

    在你的html代码中你必须这样写:

    <a href='http://www.domain.com/index/211/title-goes-here'>url_text</a>
    

    并在 htaccess 文件中修改以下内容:

    Options +SymLinksIfOwnerMatch
    
    RewriteEngine on
    
    RewriteRule ^([a-zA-Z-]+)$ index.php?action=$1 [NC,L]
    
    RewriteRule ^(member)-([0-9-]+)$ index.php?action=member&id=$2 [NC,L]
    
    RewriteRule ^([a-zA-Z-]+)/([a-zA-Z-]+)-([0-9-]+)$ index.php?action=$1&saction=$2&sid=$3 [NC,L]
    
    RewriteRule ^([a-zA-Z-]+)/([0-9-]+)$ index.php?action=$1&id=$2 [NC,L]
    
    RewriteRule ^([0-9-]+)/([a-zA-Z0-9-]+)/([a-zA-Z0-9-]+)/([a-zA-Z0-9-]+)/(.*).html$ index.php?action=details&id=$1&p1=$2&p2=$3&p3=$4 [NC,L]
    

    使用 () 标记需要提取和使用的数据;

    使用 $x,其中 x=1,2,3, ...

    $x 是值

    你拥有的 () 越多,你拥有的 $x 就越多

    with: RewriteRule ^(member)-([0-9-]+)$ index.php?action=member&id=$2 [NC,L]

    (member) 是 1 美元,([0-9]+) 是 2 美元

    你明白吗?

    【讨论】:

    • 感谢您的投票,但您明白我在那里写的内容吗?
    猜你喜欢
    • 2015-12-25
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-07-16
    • 2012-11-22
    • 1970-01-01
    • 1970-01-01
    • 2012-02-24
    相关资源
    最近更新 更多