我已经搜索这个网站好几天了,并尝试了一切来解决我的问题,但它仍然存在。我已经编写了自己的cms,现在我需要重写所有网址。具体问题是我有一个点访问槽索引.php就像现在index.php?go=users&task=add_friend
我正在尝试重写 url 以仅具有/users/add_friend
和类似内容,但始终获得没有 css 样式和 javascript 的主页。我最后一次尝试把它做好
RewriteEngine On
RewriteBase /mysite/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([A-Za-z0-9-]+)?$ index.php?go=profile&id=$1 [QSA,L]
RewriteRule ^([A-Za-z0-9-]+)/?$ index.php?go=profile&id=$1 [QSA,L]`
提前TXN
你可以尝试这样的东西吗?
RewriteEngine On
RewriteBase /mysite/
# passthrough anything that maps to a file/dir
RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^ - [L]
RewriteRule ^([A-Za-z0-9-]+)/?$ index.php?go=profile&id=$1 [QSA,L]
RewriteRule ^([A-Za-z0-9-]+)/([A-Za-z0-9-]+)/?$ index.php?go=$1&task=$2 [QSA,L]
至于你的css/js问题,你的链接可能都是相对链接,当你的URL有额外的深度(更多/
)时,你的相对URL库会发生变化,你的任何相对链接都会被破坏。您可以将它们全部设置为绝对链接,也可以在页面标题中添加相对 URL 库:
<base href="/" />
这是因为一旦你做了重写,你需要要么
使用"头"部分中的"BASE
"标记。
<base href="/">
或使用 CSS 和 JS 的完整路径
<link rel="stylesheet" type="text/css" href="/full/path/to/style.css">
然后你的css和JS就会出现。
此外,您不需要 2 条规则即可使/
可选。你可以这样做。
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([A-Za-z0-9-]+)/?$ index.php?go=profile&id=$1 [QSA,L]