htaccess RewriteRule 两个脚本

htaccess RewriteRule two scripts

美好的一天! 我的根文件夹中有两个脚本:

/index.php
/home.php

两者都接收get参数显示不同的页面,f.ex:

index.php?page=info
home.php?page=about

1) 当我尝试通过这个来清理 URI 时:

RewriteRule ^([a-zA-Z0-9]+)$ index.php?page= #working ok
RewriteRule ^([a-zA-Z0-9]+)/$ index.php?page= #doesn't load css,js

我找到了三个建议:将 css,js 文件夹的路径应用于 htaccess,使用标签或使用绝对路径。 我想知道是否有任何其他方法可以仅通过 htaccess 来制作它。或者如果有 f.ex,是否可以通过删除“/”的方式更改查询字符串: 我插入

example.org/info/

我的字符串自动变成

example.org/info

2) 我的 htaccess 只适用于 index.php。如果查询字符串中有 "userhome" 以使此类查询成为可能,我应该如何更改我的规则以使用 home.php:

example.org/home/about

P.S

RewriteRule ^home/([a-zA-Z0-9]+)$ home.php?page=

按照我需要的方式工作,关于我的第二个问题。但是我还没有解决css,js加载的问题。任何提示请

处理 CSS 未加载的最佳方法是使用 <base> 标记。这样你就可以使用相对 URL's 并且它不会违反你的规则。

这将进入您网站的 head 部分..

<base href="http://www.example.com/" />

您可以根据自己的要求尝试这些规则。

#Redirect to home.php
RewriteRule ^home/([a-zA-Z0-9]+)$ home.php?page= [L]
#Remove the trailing slash
RewriteRule ^([a-zA-Z0-9]+)/$ / [R=301,L]
#Redirect to index.php
RewriteRule ^([a-zA-Z0-9]+)$ index.php?page= [L]