【问题标题】:Force HTAccess to give a slash in end and parse the php GET values强制 HTAccess 最后给出一个斜线并解析 php GET 值
【发布时间】:2014-09-27 12:08:59
【问题描述】:

我的域名是这样排列的

localhost/editor/index.php   // This is the php file which require get variables
localhost/editor/.htaccess   // htaccess file which will pass values to index.php

HTAccess 文件:代码

RewriteEngine on
RewriteCond %{REQUEST_URI} (.*)/(.*)/
RewriteRule (.*)/(.*)/ index.php?u=$1&e=$2

我想做这样的网址

localhost/editor/variable1/variable2/

在此之后,如果有人最后会错过一个斜线,他会得到 object not found 错误 我尝试了不同的方法,但我无法解决这个问题。

【问题讨论】:

    标签: php .htaccess root url-redirection


    【解决方案1】:

    您可以改用此代码

    RewriteEngine On
    RewriteBase /editor/
    
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteRule ^([^/]+)/([^/]+)/?$ index.php?u=$1&e=$2 [L]
    

    这样就可以访问了

    localhost/editor/variable1/variable2
    

    localhost/editor/variable1/variable2/
    

    但我建议您选择一个并禁止另一个(以避免重复内容)

    【讨论】:

    • 很高兴它成功了,不客气。如果有帮助别忘了采纳我的回答
    猜你喜欢
    • 2012-12-26
    • 2013-09-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-07-22
    • 1970-01-01
    • 2021-09-21
    相关资源
    最近更新 更多