【问题标题】:Rewrite url using .htaccess in php not working在php中使用.htaccess重写url不起作用
【发布时间】:2015-12-11 09:41:43
【问题描述】:

我想重写下面的网址

http://www.example.com/page.php?n=About%2BUs&id=F534Z531G538

http://www.example.com/about-us

使用 .htaccess 文件。 我在我的 .htaccess 中尝试了以下代码

Options +FollowSymlinks
RewriteEngine on
rewriterule ^page.php?n=About%2BUs&id=F534Z531G538(.*)$ http://www.example.com/about-us$1 [r=301,nc]

但这不起作用,并且 id 也是随机生成的。

谁能帮帮我?

【问题讨论】:

    标签: php .htaccess


    【解决方案1】:

    试试这个

     RewriteRule ^about-us/([a-zA-Z0-9]+)$ page.php?id=$1
    

    http://www.example.com/about-us/f14dfa

    http://www.example.com/about-us

     RewriteRule ^about-us$ page.php
    

    【讨论】:

    • 我都试过了,它工作但不正常。此代码仅加载页面,但 css 不起作用。
    • 正确检查css链接。
    • css 链接未找到。 css 链接更改为 about-us/css/style.css。
    • 我还有一个问题是随机生成的。
    • 定义根路径并使其类似于 /css/style.css $root_url=domain.com
    猜你喜欢
    • 2014-06-06
    • 2015-09-16
    • 1970-01-01
    • 1970-01-01
    • 2014-12-26
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多