HT访问问题,结合实例实例、问题、HT

2023-09-02 01:08:53 作者:薄荷茶靡梨花白°

我的最终目标是有这样的事情。

My end goal is to have something like this.

127.0.0.1/site/search/search-term

而不是

127.0.0.1/site/search.php?term =

我已经试过两件code,第一个是。

I have tried two pieces of code, first being.

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ ../search.php?term=$1

和我把这个名为/搜索文件夹内。 htaccess的作品完美,但CSS被弄乱了我的网站,它只是显示一切以纯文本没有任何造型。

And i put this inside a folder called /search. The HTACCESS works perfectly but the css gets messed up for my website, it just shows everything as plain text without any styling.

其次我试图

RewriteEngine On
RewriteBase /search/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ ../search.php?term=$1

和投入,在127.0.0.1/site/根。但是,当我试图127.0.0.1/site/search/searchterm我收到了404。

And put that in 127.0.0.1/site/ root. But when i tried 127.0.0.1/site/search/searchterm I get a 404.

任何人都可以看到我错了?我猜第一个选项是最好的努力得到修复,因为它是如此之近的工作,我期待通过页面的源代码我使用vainty URL后获得,我认为它可能是做IM如何贯通样式表?它的工作原理,如果我把完整的地址的链接(127.0.0.1/site/main.css)但后来都失败对我所有的jQuery包含等是否明智只是把当过我想要的详细地址使用虚荣网址?

Can anyone see where i am going wrong? I am guessing the first option is the best one to work towards getting fixed as it is so close, i look through the source of the page i receive after using the vainty url and i think it might be something to do with how im linking the style sheet? It works if i put the full address in for the link (127.0.0.1/site/main.css) But then all it fails on all my jquery includes etc. Is it wise to just put the full address in when ever i want to use vanity urls?

推荐答案

首先要确保你使用的CSS绝对路径,JS和图片文件。也就是说路径对这些资源要么以斜线开始 / 的http:// 。如果你不已经拥有了它,那么请进行必要code的变化。一旦做到这一点使用下面的.htaccess中 $ DOCUMENT_ROOT (不 $ DOCUMENT_ROOT /网站

First make sure you're using absolute paths in CSS, JS and images files. That means path to these resources should either start with a slash / or http://. If you don't already have it then please make necessary code changes. Once that is done use following .htaccess in $DOCUMENT_ROOT (not in $DOCUMENT_ROOT/site):

Options +FollowSymLinks -MultiViews
# Turn mod_rewrite on
RewriteEngine On
RewriteBase /

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-l
RewriteRule ^site/search/(.+)/?$ site/search.php?term=$1 [L,QSA,NC]

编辑:按这里您的意见是code键使小写的一个URI:

As per your comments here is the code to make a URI in lowercase:

先在部分或httpd.conf文件的末尾添加下面一行

First add this line in section OR at the end of your httpd.conf file:

RewriteMap lc int:tolower

然后让你的规则是这样的:

Then have your rules like this:

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-l
RewriteRule ^site/search/(.+)/?$ site/search.php?term=${lc:$1] [L,QSA,NC]