简体   繁体   中英

.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. I am using last version of WAMP and this time .htaccess drives me crazy. No RewriteBase.

Apache modules are activated for redirection and all should work, example with :

RewriteRule ^test$ trying.php [L]

and trying.php is like :

<?php
echo "lol";
?>

I have :

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 :

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

and I obtain :

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.

Then I try the real thing, accessing an existing member at this address http://localhost/try/member/member1 and I am redirected to...

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

It is a [L] redirection not a [R], so why is that happening ? Why does it happen only with existing members ? I restarted WAMP services each time, no explanation.

You need to have correct RewriteBase . Inside your /try/.htaccess have it like this:

Options +FollowSymLinks -MultiViews
RewriteEngine On
RewriteBase /try/

RewriteRule ^test$ trying.php [L]

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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