【问题标题】:how to use .htaccess to rewrite rule?如何使用 .htaccess 重写规则?
【发布时间】:2018-06-08 13:21:40
【问题描述】:

我正在做一个需要 SEO 的项目,对于 SEO,它需要用户友好的 URL,我想让我的 url 看起来对用户友好,这是我的 .htaccess 代码,我想让我的 url 看起来像:

http://localhost/footboleh/article/Some-text

虽然目前它看起来像:

http://localhost/footboleh/article?url=Some-text

.ht访问代码:

RewriteEngine on

RewriteCond %{REQUEST_FILENAME} !-f

RewriteCond %{REQUEST_FILENAME} !-d

RewriteRule ^(.*)$ article.php?url=$1 [QSA,L]

我尝试了一些重写规则,这些规则是

RewriteRule ^(.*)$ article.php?url=$1 [QSA,L]

它给我带来了没有 css 和 js 的索引页面,并在控制台中给出错误 控制台错误:

Uncaught SyntaxError: Unexpected token

我有 print_r ($_GET] 它的节目:

数组([url] => 文章/some-text.php)

【问题讨论】:

    标签: php .htaccess


    【解决方案1】:

    您需要从重写中排除您的 css 和 js 文件,通常通过:

    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    

    就在你的重写行之前。

    【讨论】:

    • 所以你的 css/js 还没有出现?发布您的 htaccess 现在的样子。
    • RewriteEngine on RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule ^(.*)$ article.php?url=$1 [QSA,L]
    • 看起来不错。如果你直接在浏览器中访问,你的 css/js 会加载吗?
    • 不,如果您有 htaccess 文件,如果您尝试访问 yoursite.com/yourcssfile.css 会发生什么?你看到你的 css 文件打印出来了吗?
    • 是的,哥们,它显示了所有的 js 函数和 css 类
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-02-25
    • 1970-01-01
    • 2011-11-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多