简体   繁体   English

.htaccess在“有时”工作并且不喜欢相对链接

[英].htaccess working “sometimes” and doesn't like relative links

I am working on a project right now, after other projects some weeks ago using also .htaccess redirection without any problem. 我正在一个项目上工作,几周前在其他项目之后也使用.htaccess重定向没有任何问题。 I am using last version of WAMP and this time .htaccess drives me crazy. 我正在使用最新版本的WAMP,这一次.htaccess使我发疯。 No RewriteBase. 没有RewriteBase。

Apache modules are activated for redirection and all should work, example with : 已激活Apache模块以进行重定向,并且所有模块都应正常工作,例如:

RewriteRule ^test$ trying.php [L]

and trying.php is like : 而try.php就像:

<?php
echo "lol";
?>

I have : 我有 :

ex1 http://img11.hostingpics.net/pics/180473es1.png ex1 http://img11.hostingpics.net/pics/180473es1.png

So right, it should work ! 好吧,它应该工作! I then try to access a member page but this member doesn't exist so there only should be the title of the page in the header, my .htaccess is like : 然后,我尝试访问成员页面,但该成员不存在,因此标题中应仅包含页面标题,我的.htaccess类似于:

RewriteRule ^member/([A-Za-z0-9]+)$ member.php?id=$1 [L]

and I obtain : 我得到:

ex2 http://img11.hostingpics.net/pics/336923es2.png ex2 http://img11.hostingpics.net/pics/336923es2.png

So I have the page without information on the user (as expected) except the title but it doesn't find the css file (relative link to it in the header), not good. 所以我有一个页面,除了标题外,没有关于用户的信息(如预期的那样),但是找不到css文件(在标题中有相对链接),不好。

Then I try the real thing, accessing an existing member at this address http://localhost/try/member/member1 and I am redirected to... 然后,我尝试使用真实的东西,访问此地址http://localhost/try/member/member1的现有成员,然后将我重定向到...

ex3 http://img11.hostingpics.net/pics/480421es3.png ex3 http://img11.hostingpics.net/pics/480421es3.png

It is a [L] redirection not a [R], so why is that happening ? 这是[L]重定向而不是[R],为什么会发生这种情况? Why does it happen only with existing members ? 为什么只在现有成员中发生? I restarted WAMP services each time, no explanation. 我每次都重新启动WAMP服务,没有任何解释。

You need to have correct RewriteBase . 您需要具有正确的RewriteBase Inside your /try/.htaccess have it like this: 在您的/try/.htaccess内部,如下所示:

Options +FollowSymLinks -MultiViews
RewriteEngine On
RewriteBase /try/

RewriteRule ^test$ trying.php [L]

RewriteRule ^member/([A-Z0-9]+)/?$ member.php?id=$1 [NC,L,QSA]

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM