【问题标题】:php url friendly withhtaccess and get variablesphp url友好withhtaccess并获取变量
【发布时间】:2013-04-18 16:50:11
【问题描述】:

谁能帮我提供用户友好的 URL 并获取变量。

我的文件名为 test.php,我正在使用 htaccess 删除 url 的 .php 部分。 理论上我想要以下格式的以下url构造: www.example.com/test/1234

其中 1234 是我的 id= 部分

什么是最好的方法,我该怎么做?

到目前为止,这是我的 htaccess:

Options -Indexes

RewriteEngine  on
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule !.*\.php$ %{REQUEST_FILENAME}.php [L, QSA]

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

我正在尝试通过以下方式获取 get 变量:

$var = $_GET['id'];

echo $var;

任何帮助将不胜感激。将来我将使用它来传递产品名称并将它们用作获取变量以增加 seo 和用户体验。如果您需要更多信息或任何问题,我很乐意回复

【问题讨论】:

    标签: php url-rewriting


    【解决方案1】:

    你能看看这是否有效吗?

    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-l
    
     RewriteRule ^test/(.+)$ test.php?id=$1 [QSA,L]
    

    ^ 以上作品

    【讨论】:

    • 嗨,这回显了以下内容: test/123 但是 test 是文件名,即 test.php
    • Dinesh - 谢谢你的帮助,我已经破解了。 RewriteRule ^test/(.+)$ test.php?id=$1 [QSA,L] - 这行得通:)
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2015-07-02
    • 2016-04-13
    • 2014-02-02
    • 2011-12-17
    • 2014-10-02
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多