1

我有一个站点,它已经定义了 htaccess 以使 url 更好

DirectoryIndex index.php
RewriteEngine On
RewriteBase /

Options -indexes

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

RewriteRule (.*) index.php

一切正常(根文件夹中有 cms)。

现在我想在根目录中创建一个文件夹并为其制定另一个规则:

DirectoryIndex index.php
RewriteEngine On
RewriteBase /

Options -indexes

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !tip [NC]

RewriteRule (.*) index.php [NC]

RewriteCond %{QUERY_STRING} ^$
RewriteRule ^tip/([^/]+)/? /tip/?id=$1

所以我想从 url 重定向所有内容:.../tip/?id=N->../tip/N

它似乎工作正常,传递了 id,但加载了数据。网站内的所有网址都是错误的(javascript、css)。它们没有加载。

看:http ://wincode.org/tip/3

例如,代码:<script defer src="js/filtrify.js"></script>产生:http://wincode.org/tip/js/filtrify.js但如果您尝试将其加载到另一个选项卡中,我认为它将js/filtrify.js作为id参数传递。如何解决这个问题?

4

2 回答 2

3

A. 在 $DOCUMENT_ROOT/.htaccess 中更改您的 .htaccess 代码:

DirectoryIndex index.php
RewriteEngine On
RewriteBase /

Options -indexes

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-l
RewriteRule (?!^tip(/.*|)$)^.*$ /index.php [L,NC]

B. 在 $DOCUMENT_ROOT/tip/.htaccess 中更改您的 .htaccess 代码:

DirectoryIndex index.php
RewriteEngine On
RewriteBase /tip

Options -indexes

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-l
RewriteCond %{QUERY_STRING} ^$
RewriteRule ^([^/]+)/?$ /tip/?id=$1 [L,QSA]
于 2013-03-15T10:45:14.080 回答
0

我只是改进了一点 anubhava 回复,这个是基于根文件夹的例子,但是你可以对你需要的其他目录使用相同的方法。

DirectoryIndex index.php
<IfModule mod_rewrite.c>
  RewriteEngine On
  RewriteBase /

  Options -indexes

  RewriteCond %{REQUEST_FILENAME} !-f
  RewriteCond %{REQUEST_FILENAME} !-d
  RewriteCond %{REQUEST_FILENAME} !-l
  RewriteRule (?!^tip(/.*|)$)^.*$ /index.php [L,NC]
</IfModule>

<IfModule !mod_rewrite.c>
    # Mod_rewrite not installed, redirect all 404 errors to index.php.
    ErrorDocument 404 index.php
</IfModule>
于 2015-06-24T14:22:58.637 回答