1

私はURLを素敵にするためのhtaccessをすでに定義しているサイトを持っています

DirectoryIndex index.php
RewriteEngine On
RewriteBase /

Options -indexes

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

RewriteRule (.*) index.php

すべて正常に動作します(ルートフォルダにcmsがあります)。

ここで、root内にフォルダーを作成し、そのための別のルールを作成します。

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が渡され、データがロードされますが。サイト内のすべてのURLが間違っています(javascript、css)。それらはロードされません。

見てください:http ://wincode.org/tip/3

たとえば、code:<script defer src="js/filtrify.js"></script>produces: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 に答える