【问题标题】:.htaccess rewrite URL for my website.htaccess 重写我网站的 URL
【发布时间】:2016-10-13 14:16:44
【问题描述】:

也许你可以帮我重写我的 URL(我从未使用过 .htacces 文件)。

示例: 我有一个这样的网址:http://localhost/index.php?s=example

我怎样才能找到这样的 URL:http://localhost/example?

也许你可以帮助我。

谢谢!

【问题讨论】:

    标签: .htaccess url-rewriting


    【解决方案1】:

    您可以在root/.htaccess中使用以下内容

    RewriteEngine on
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^([^/]+)/?$ /index.php?s=$1 [NC,L]
    

    此脚本将允许您使用干净的 url /foobar 访问 /index.php?s=foobar

    【讨论】:

    • 感谢您的回答!但是你对 root/.htaccess 是什么意思?以及如何使用此解决方案获得 $_GET['index']?
    • @iseven Root/.htaccess 是位于 root/public_html 文件夹中的 htaccess 文件。您可以在 php 页面中使用 $_GET["s"] 访问/获取 uri /foobar 的动态值
    • 您好,这可以在我的本地机器上使用 xampp 吗?它实际上对我不起作用..还有其他设置吗?我必须在我的 php 页面中使用 $_GET['s'] 吗?
    • 嗨,这在我的服务器上运行良好。至于我认为你实际上不知道 url-rewriting 是如何工作的,请看一下基本的httpd.apache.org/docs/current/mod/mod_rewrite.html
    猜你喜欢
    • 2015-02-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-04-29
    • 2012-10-31
    • 2011-12-03
    • 2014-01-07
    相关资源
    最近更新 更多