I am having a problem with rewriterule,
None of this works, and I know the file htaccess works etc.. Can anyone help, I changed \ to / etc..
RewriteRule ^cover-([0-9]+)/.html$ view.php?cover=$1
RewriteRule ^sendcover-([0-9]+)/.html$ send_cover.php?cover=$1
RewriteRule ^index\.html$ index.php
RewriteRule ^page-([0-9]+)/.html$ page.php?pid=$1
RewriteRule ^success\.html$ index.php?er=success
RewriteRule ^unknown-error/.html$ index.php?er=un_error
RewriteRule ^width/.html$ index.php?er=width
RewriteRule ^height/.html$ index.php?er=height
The only thing really wrong with those rules is that /.html should really be \.html
With / it is never going to work, since that will literally match a slash in the URL.
The reason you use \. instead of . in the URL is that in regular expressions . matches any character. Unless you "escape" it with a \ to take away that special meaning so it just matches a dot.
1) Do you know on which version of Apache you are? If you are on 1.x (highly unlikely since it's very old), you need to start of the RewriteRules with ^/ instead of just ^
2) If you rewrite to (for the first rule) /view.php?cover=$1 instead of view.php?cover=$1, does it work then? (probably not, but on some hosts adding a leading slash fixes things -- more specifically, on hosts that use Mass Virtual Hosting)
3) You should add [L] at the end of all of those rules to tell Apache to stop matching once it's found a match. This won't fix anything for you, but it will make the code more efficient (once it works)
If none of that fixes it you should probably check if mod_rewrite is enabled in the first place (by either checking yourself if you have admin access to the server, or asking your hoster if you don').
I would like to thank you so much for your help, that indeed worked and I am so grateful for your help through this.
I followed all your simple steps and voila, it worked.
Thanks again! If there's anything I can do for you, please state so
I wanted to clear this part up real quick, because this has been spreading around the forums. Both Apache 1.x and Apache 2.x actually behave in exactly the same way with regard to the leading slash. See my full explanation, which contains references to the documentation and repeatable steps to verify this behavior.
Huh, I've spreading wrong information for a few years now it would seem (although it probably doesn't matter much since no-one has been using Apache 1.x for ages, I hope!). Thanks for putting my head straight
@dklynn; should read this too, as I'm pretty sure he's making the same mistake I am.
Naw, that was a MAJOR difference when Apache 2 came out. If things have changed as Jeff suggests, then it's a recent development. That said, anyone using Apache 1 must be using an ancient version (no reason not to update to Apache 2) and Apache 2 has declined to match the leading /.
The per-server and per-directory behavior is in the documentation at least as far back as Apache 1.3. I even installed 1.3 to test it (you could do the same). This isn't a recent development. It's always been this way.
This topic is now closed. New replies are no longer allowed.