【问题标题】:error with friendly URL with .htaccess and relative files带有 .htaccess 和相关文件的友好 URL 错误
【发布时间】:2014-06-04 07:01:58
【问题描述】:

我制作了一个 .htaccess 文件来使我的 URL 看起来像 http://www.domain.com/ar/?page=article&id=20http://www.domain.com/ar/article/20

到目前为止,我已经做到了

Options -ExecCGI +Includes -IncludesNOEXEC -Indexes -SymLinksIfOwnerMatch
RewriteEngine On
RewriteRule ^([^/]*)/([^/]*)$ /ar/?page=$1&id=$2 [L]

但是.. 所有文件(css,js,图像)都被破坏了..我试图尽可能地使其绝对化(通过在每个 src 的开头添加 /),但没有运气

.. 如何加载文件?

如何将网址从 (?page=contact 重定向到 ar/contact .. 而不是 ar/topic/20/?page=contact)?

以及如何在我的网址中包含任何其他意外参数??

【问题讨论】:

  • 没有你的遗言?

标签: php html .htaccess


【解决方案1】:

我不太确定,但试试这个。

Options +FollowSymLinks
RewriteEngine On
# with html base href in header: <base href="http://<?=$_SERVER['HTTP_HOST']?>/" />
RewriteBase /
# deny rules to url rewrite for specific file types in website root folder
RewriteRule ^/?(.*).(php|css|ico|js|log|png|jpg|gif|jpeg)$ - [L]
# deny rules to url rewrite for folders (if needed)
RewriteRule ^(css|images)($|/) - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
# and the mapping rule. index.php is your basic file for example
# $1 -> ar/ $2 -> article/$3 -> 20
RewriteRule ^([^/]*)/([^/]*)/([^/]*)$ index.php?module=$1&page=$2&id=$3 [L]
Options SymLinksIfOwnerMatch

【讨论】:

    【解决方案2】:

    您需要在重写规则中添加一个条件。试试这个。

    Options -ExecCGI +Includes -IncludesNOEXEC -Indexes -SymLinksIfOwnerMatch
    RewriteEngine On
    RewriteCond %{REQUEST_URI} !.*\.(css¦jpg¦gif¦png¦js)
    RewriteRule ^([^/]*)/([^/]*)$ /ar/?page=$1&id=$2 [L]
    

    如果请求的文件没有 CSS、JPG、GIF、PNG 或 JS 的扩展名,这只会重写 URL。

    编辑更正了一个语法错误。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2014-02-26
      • 2013-03-24
      • 1970-01-01
      • 1970-01-01
      • 2019-11-08
      • 2014-10-04
      • 2015-12-16
      • 2014-11-24
      相关资源
      最近更新 更多