我有一个网站,它已经定义了使网址更好的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所以我想重定向来自../tip/N的所有内容:.../tip/?id=N -> url
它似乎工作得很好,id被传递,数据被加载,但是。所有的urls在站点内部都是错误的(javascript,css)。他们没有上膛。
查看:http://wincode.org/tip/3
例如,代码:<script defer src="js/filtrify.js"></script> produces:http://wincode.org/tip/js/filtrify.js,但如果您尝试在另一个选项卡中加载它,我想它会将js/filtrify.js作为id参数传递。如何解决这个问题?
发布于 2013-03-15 18:45:14
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]发布于 2015-06-24 22:22:59
我只是稍微改进了一个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>https://stackoverflow.com/questions/15429954
复制相似问题