views:

207

answers:

2

Recently, I was doing .htaccess url rewrite, make all my php url into html, in some page, the logout button wont work properly. for example, in page ‘quotedetails/Q9999.html’ (rewrited from ‘quotedetails.php?quoteID=Q9999′), when I click logout button in this page, it wont do the trick, but when i use the old php url of this page, it works again, other rewrited pages like index.html (index.php), search.html(search.php), all works perfectly.

I use firebug to debug, after I click the logout button, it stays in the same page without redirect me to the index.html, but I saw the the ‘logoff’ params has been passed through, but just dont let me logout and redirect to index page. I’ve changed all the relavent file path to absolute path, still no luck…..help please.

I’ve also noticed from firebug, that page cannot get the redirect ‘location’ as I tried in other pages, their response headers come with ‘location: index.html’, but in that no-workin-page, there is no such line called ‘location: index.html’ in its response headers.

Here is my .htaccess file, no-workin-pages are related to the first four ReweiteRules

Options +FollowSymlinks
RewriteEngine on

RewriteRule ^reps/all,all.html$ rep.php?repID=all&repName=all   
RewriteRule ^reps/([A-Z]+),([A-Za-z\sA-Za-z]+).html$ rep.php?repID=$1&repName=$2
RewriteRule ^reps/([A-Za-z]+),([A-Za-z\sA-Za-z]+),([0-9]+).html$ rep.php?repID=$1repName=$2&page=$3
RewriteRule ^quotedetails/(Q[0-9]+).html$ quotedetails.php?quoteID=$1

RewriteRule ^index.html$ index.php   
RewriteRule ^addquote.html$ addquote.php   
RewriteRule ^search.html$ search.php   
RewriteRule ^viewall.html$ viewall.php   
RewriteRule ^howto.html$ howto.php   
+1  A: 

all the CSS will be lost, how to fix this issue?

Use absolute path for all the CSS files and images

I click log out button, its not working

You have to do at least initial debug. Nobody here knows, what's going on when you press a button. Go figure.

Col. Shrapnel
thank you, i put the css path like: href="css/my_layout.css" so as the js files. what should put up in there? I currently run the website from localhost by using xampp, so the absolute path should be href="htdocs/test(my website folder)/css/my_layout.css" ?
Patrick
@Patrick `/test(my website folder)/css/my_layout.css` but I strongly recommend you to make another virtual server with it's own htdocs folder, to elimitate /test(my website folder)/ from the path. So, the url to CSS file become `http://testsite.com/css/my_layout.css` and path - `/css/my_layout.css`. The last one is one icalled "absolute", i.e. starting from the `/`
Col. Shrapnel
ok I will try your method rite now. did you mean to set up a new vitual server and put all the webpages in the root dir?
Patrick
yes. I have never used a xampp but I am sure it can let you create different virtual hosts for the different sites.
Col. Shrapnel
i tried, it works.There is one more problem is that after i change my url style to quotedetails/Q9999.html (used to be quotedetails.php?quoteID=Q9999), all the links in that page become inside 'quotedetails' folder, for example, index.html link become to 'quotedetails/index.html'. how to solve this issue? I think it must be something wrong with my .htaccess and the regular expression. help please!! many thanks!
Patrick
@Patrick Make it all absolute. `/index.html`, `/css/my_layout.css` and so on. Starting from the slash followed by the full real path to the script from the server root
Col. Shrapnel
oh i only make all the js css images with absolute path, I will make them all then, cheers! I'll mark your answers as accepted! thank you, I'll figure out the logout issue by myself.
Patrick
@Patrick the absolute path thing is very necessary for the every webmaster. One important thing with it: there are files and there are URLs. they are differ. a file's absolute path starts from the disk root, like `c:\xampp\test\css\my_layout.css` or `/var/www/testsite.com/hrml/scc/my_layout.css` - these 2 are files. At the same time these can be urls, starting from the web-server root, with `/scc/my_layout.css` absolute path. Do not mix these 2 matters. You will need files to deal with them from PHP and URLS to use in HTML. And don't hesitate to ask about login too. Just determine the point
Col. Shrapnel
hi Col, I've updated the post with some detail info about the login problem, please have a look at, thank you Col.
Patrick
A: 

You don't have to use absolute paths... most people just forget about one of the most important html-tags. write this into your -section of your html-output:

<base href="http://mysite.com" />

Now all your css-files and images should be loaded correctly.

faileN
base href is not an option. and this one is ridiculous
Col. Shrapnel
no it's not. his page doesn't find the css file, because he wants to use slashes in his url-rewriting. the page thinks, that the css-file is relative to the current page, for example http://mysite.com/news/style.css. but of course it's not there. with the html-base-tag you can avoid this, because all relative paths will use this url as base. that's what the tag was invented for.
faileN
thanks a lot, I currently run the website from localhost by using xampp, so the code should be <base href="http://localhost/test/" /> ?
Patrick
Yep that's right.
faileN
1. writing a hostname as a base href is a nonsense. the same effect can be achieved by just adding a slash to the file path. 2. there can be some *real relative links*, not lame ones. base href is useless thing.
Col. Shrapnel
Ok, your're right. You could just write a Slash or in your case "/test/". That there are some "real relative paths" shouldn't bother you, as long as you apply them to the base that you give in your base tag.
faileN
Just tested it. A file from the same directory was not found because browser was looking for in th the base href directory. Man, it could mess everything.
Col. Shrapnel
hi, your method is easier to implement but it causes some other issues, I have a some empty links (href="#") to call up some jQuery functions, but when i click it, the whole page jump back to index.html, how to aviod that? thank you!
Patrick
@ Col. Shrapnel: how did you test it? With what statement? Including a picture, css-file, js-file?@Patrick: Unfortunately I'm not used to jQuery (not yet)... Of course empty links is a problem and I unfortunately again, I don't know how t avoid that issues. The only thing, that you could do, ist to rewrite the link-targets.For example you are on page http://localhost/test/news/foobar.html and want to use such an empty link you could reach that by <a href="/news/html#">...Or wait a minute. Why do you use a "#" character as href-value? Is it, beacause you use the onclick-attribute for jq?
faileN
if so, than you could probably do something like <a href="javascript: void();" onclick="...do jQuery-stuff">Link</a>
faileN