SitePoint Sponsor

User Tag List

Results 1 to 16 of 16
  1. #1
    SitePoint Member
    Join Date
    Apr 2013
    Posts
    5
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)

    My .htaccess doesnt work

    My .htaccess doesn't work fine, only work three rules from four.

    RewriteEngine On
    RewriteBase /

    RewriteRule ^prensa$ /prensa.php?seo=prensa [L]
    RewriteRule ^/?$ /index.php [L]
    RewriteRule ^noticias$ /prensa.php?seo=noticias
    RewriteRule ^([^\.\?/]+)?$ /pagina.php?seo=$1 [L]

    For example:

    when I write www.myweb.com/bodas work well and get www.myweb.com/pagina.php?seo=boda

    the same with www.myweb.com/noticias www.myweb.com/prensa.php?seo=noticias

    but when I write www.myweb.com/prensa I get www.myweb.com/prensa.php, I dont return the right solution. Why?

    I read http://datakoncepts.com/seo but I dont know my htaccess works so bad.

    Thanks.

  2. #2
    Certified Ethical Hacker silver trophybronze trophy dklynn's Avatar
    Join Date
    Feb 2002
    Location
    Auckland
    Posts
    14,656
    Mentioned
    19 Post(s)
    Tagged
    3 Thread(s)
    monchy,

    Three for four isn't a bad average! Take heart in that.

    I'm definitely not fond of the RewriteBase directive as that generally causes more problems than it resolves but your first three cases are good.

    Code:
    RewriteRule ^([^\.\?/]+)?$ /pagina.php?seo=$1 [L]
    Here you've begun the character range definition by escaping the dot character (which is NOT required in a character range definition) then by escaping a ?. Unfortunately (and the reason it's not working for you), the ? is a reserved character (http://www.ietf.org/rfc/rfc2396.txt) which cannot be within a {REQUEST_URI} string (you may be able to encode it but I'd have to check the link above to verify that) because it's the demarcation character defining the end of the {REQUEST_URI} string and the start of the {QUERY_STRING}. Of course, if you need to access the query string in mod_rewrite, you must do so with a RewriteCond statement.

    So, other than not understanding the allowed content of URIs, I'd say that you've done very well.

    Regards,

    DK
    David K. Lynn - Data Koncepts is a long-time WebHostingBuzz (US/UK)
    Client and (unpaid) WHB Ambassador
    mod_rewrite Tutorial Article (setup, config, test & write
    mod_rewrite regex w/sample code) and Code Generator

  3. #3
    SitePoint Member
    Join Date
    Apr 2013
    Posts
    5
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    Thanks dklynn,

    Quote Originally Posted by dklynn View Post

    So, other than not understanding the allowed content of URIs, I'd say that you've done very well.
    I understand and I change. My case is so strange because if I change the first rule for this:

    RewriteRule ^Prensa$ /prensa.php?seo=prensa [L]

    If I change prensa for Prensa all is right, why?

  4. #4
    SitePoint Wizard bronze trophy Jeff Mott's Avatar
    Join Date
    Jul 2009
    Posts
    1,277
    Mentioned
    18 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by monchyrcg View Post
    but when I write www.myweb.com/prensa I get www.myweb.com/prensa.php, I dont return the right solution. Why?
    I feel like there must be more to this htaccess than what we're seeing, because as is, it looks like it should work correctly.

    My case is so strange because if I change the first rule for this:

    RewriteRule ^Prensa$ /prensa.php?seo=prensa [L]

    If I change prensa for Prensa all is right, why?
    Does your URL in the address bar have a capital P?
    "First make it work. Then make it better."

  5. #5
    SitePoint Member
    Join Date
    Apr 2013
    Posts
    5
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    I'm doing a cms and I can change de url in the admin so I can put any word in the url. I dont understand what is the problem.

  6. #6
    Certified Ethical Hacker silver trophybronze trophy dklynn's Avatar
    Join Date
    Feb 2002
    Location
    Auckland
    Posts
    14,656
    Mentioned
    19 Post(s)
    Tagged
    3 Thread(s)
    monchy,

    Jeff simply didn't read the character definition in your code correctly. Saying that, I'm sure that he does know that RewriteRules cannot examine the query string AND that the question mark is a reserved character (which should only be in a URL to separate the URI from the query string).

    Quote Originally Posted by http://www.ietf.org/rfc/rfc2396.txt
    2.2. Reserved Characters

    Many URI include components consisting of or delimited by, certain
    special characters. These characters are called "reserved", since
    their usage within the URI component is limited to their reserved
    purpose. If the data for a URI component would conflict with the
    reserved purpose, then the conflicting data must be escaped before
    forming the URI.

    reserved = ";" | "/" | "?" | ":" | "@" | "&" | "=" | "+" |
    "$" | ","

    The "reserved" syntax class above refers to those characters that are
    allowed within a URI, but which may not be allowed within a
    particular component of the generic URI syntax; they are used as
    delimiters of the components described in Section 3.
    It makes no matter whether you want to match the P or p so long as you are consistent. If you want to match both, use

    Code:
    RewriteRule ^P|prensa$ /prensa.php?seo=prensa [L]
    With the OR bar between the P and p, the regex will match both Prensa and prensa (if the only content of the URI string).

    Regards,

    DK
    David K. Lynn - Data Koncepts is a long-time WebHostingBuzz (US/UK)
    Client and (unpaid) WHB Ambassador
    mod_rewrite Tutorial Article (setup, config, test & write
    mod_rewrite regex w/sample code) and Code Generator

  7. #7
    SitePoint Wizard bronze trophy Jeff Mott's Avatar
    Join Date
    Jul 2009
    Posts
    1,277
    Mentioned
    18 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by dklynn View Post
    Jeff simply didn't read the character definition in your code correctly. Saying that, I'm sure that he does know that RewriteRules cannot examine the query string AND that the question mark is a reserved character (which should only be in a URL to separate the URI from the query string).
    Actually I read the character definition just fine. Matching on non-question mark characters isn't causing any issues. It may be unnecessary, but it's not problematic.

    Furthermore, the OP's issue isn't related to the forth rewrite rule, but the first. As the OP described, prensa is supposed to rewrite to /prensa.php?seo=prensa, but instead it's rewriting to just /prensa.php. I reiterate that I don't see anything in this htaccess that explains this behavior, nor do I see anything that explains why using a capital "P" in the URL would make it work. And so I still believe that there must be more to this htaccess than what we've seen.
    "First make it work. Then make it better."

  8. #8
    SitePoint Member
    Join Date
    Apr 2013
    Posts
    5
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by Jeff Mott View Post
    I reiterate that I don't see anything in this htaccess that explains this behavior, nor do I see anything that explains why using a capital "P" in the URL would make it work. And so I still believe that there must be more to this htaccess than what we've seen.
    I promise that I worte all the .htaccess. About capital letter is so strange but work.

  9. #9
    SitePoint Member
    Join Date
    Apr 2013
    Posts
    5
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    I have another doubt how to use ExpiresActive in my htcaccess i put:

    <IfModule mod_expires.c>
    # Enable expirations.
    ExpiresActive On
    ExpiresDefault A3600
    <filesmatch ".(jpg|JPG|gif|GIF|png|css|ico|js)$">
    ExpiresDefault "access plus 7 day"
    </filesmatch>
    </IfModule>

    RewriteEngine On
    RewriteBase /

    RewriteRule ^P|prensa$ /prensa.php?seo=prensa [L]
    RewriteRule ^/?$ /index.php [L]
    RewriteRule ^noticias$ /prensa.php?seo=noticias
    RewriteRule ^([^\.\?/]+)?$ /pagina.php?seo=$1 [L]

    Don't work, when I try to access, return and error 500 internal server error. I use phpinfo() to know if the module mod_expires.c and I think that yes Thanks.

    I dont know why but the error appears when I write anything in the if sentence

    <IfModule mod_expires.c>
    # Enable expirations.

    <filesmatch ".(jpg|JPG|gif|GIF|png|css|ico|js)$">

    </filesmatch>
    </IfModule>

    If I put this I have no errors.

  10. #10
    Certified Ethical Hacker silver trophybronze trophy dklynn's Avatar
    Join Date
    Feb 2002
    Location
    Auckland
    Posts
    14,656
    Mentioned
    19 Post(s)
    Tagged
    3 Thread(s)
    monchy,

    [standard rant #4]
    The definition of an idiot is someone who repeatedly does the same thing expecting a different result. Asking Apache to confirm the existence of ANY module with an <IfModule> ... </IfModule> wrapper is the same thing in the webmaster world. DON'T BE AN IDIOT! If you don't know whether a module is enabled, run the test ONCE then REMOVE the wrapper as it is EXTREMELY wasteful of Apache's resources (and should NEVER be allowed on a shared server).
    [/standard rant #4]

    Okay, that's NOT to call you an idiot, it's simply to remind you in the clearest terms possible that any webmaster would only run ONE server test, not repeat server tests multiple times for EVERY request!

    You also need to learn which characters are considered metacharacters with a character range definition as it seems that you've gone "escape crazy" by escaping every character (none of which needs escaped except the ? which should not be there in the first place).

    You might benefit from reading the mod_rewrite tutorial linked in my signature as it contains explanations and sample code. It's helped may members and should help you, too.

    Regards,

    DK
    David K. Lynn - Data Koncepts is a long-time WebHostingBuzz (US/UK)
    Client and (unpaid) WHB Ambassador
    mod_rewrite Tutorial Article (setup, config, test & write
    mod_rewrite regex w/sample code) and Code Generator

  11. #11
    SitePoint Wizard bronze trophy Jeff Mott's Avatar
    Join Date
    Jul 2009
    Posts
    1,277
    Mentioned
    18 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by dklynn View Post
    You might benefit from reading the mod_rewrite tutorial linked in my signature as it contains explanations and sample code. It's helped may members and should help you, too.
    Obligatory note:

    Unfortunately anyone who learns from this tutorial will have to unlearn some incorrect information later on. I strongly recommend that anyone who's interested in this topic go straight to the definitive source for the most complete, authoritative, and correct information.
    "First make it work. Then make it better."

  12. #12
    Certified Ethical Hacker silver trophybronze trophy dklynn's Avatar
    Join Date
    Feb 2002
    Location
    Auckland
    Posts
    14,656
    Mentioned
    19 Post(s)
    Tagged
    3 Thread(s)
    Jeff,

    Sorry, I'd have to give the same advice to others about your insistence on using (.*) inappropriately (among other things you've come up with).

    As for going straight to Apache.org, I agree. However, their documentation is too "geeky" for most so my tutorial was written to make life easier for SitePoint members ... and has received high praise from everyone (other than you - your comment is the first of its nature in the 5+ years it's been online).

    Members,

    Take all advice here with a grain of salt, i.e., consider the source.

    Regards,

    DK
    David K. Lynn - Data Koncepts is a long-time WebHostingBuzz (US/UK)
    Client and (unpaid) WHB Ambassador
    mod_rewrite Tutorial Article (setup, config, test & write
    mod_rewrite regex w/sample code) and Code Generator

  13. #13
    SitePoint Wizard bronze trophy Jeff Mott's Avatar
    Join Date
    Jul 2009
    Posts
    1,277
    Mentioned
    18 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by dklynn View Post
    Sorry, I'd have to give the same advice to others about your insistence on using (.*) inappropriately (among other things you've come up with).
    My "insistence" on using .* comes straight from the Apache documentation. They use it in the same way I do.

    Quote Originally Posted by dklynn View Post
    As for going straight to Apache.org, I agree. However, their documentation is too "geeky" for most so my tutorial was written to make life easier for SitePoint members
    Unfortunately your tutorial, in a number of places, contradicts the documentation, and it contradicts observable behavior in Apache.
    "First make it work. Then make it better."

  14. #14
    Utopia, Inc. silver trophy
    ScallioXTX's Avatar
    Join Date
    Aug 2008
    Location
    The Netherlands
    Posts
    9,084
    Mentioned
    153 Post(s)
    Tagged
    2 Thread(s)
    /x.php exists, and a RewriteRule to from /x to /x.php doesn't work. Hmm, that rings a bell.

    DK, we've seen this bugger before quite a few times, you should recognize the smell of this stinky old friend by now.

    @monchyrcg ; start your .htacces with

    Code:
    Options -MultiViews
    and everythig will work as planned.

    Seriously, I still don't understand why that option even exists in Apache, let alone why someone would turn it on
    Rémon - Hosting Advisor

    SitePoint forums will switch to Discourse soon! Make sure you're ready for it!

    Minimal Bookmarks Tree
    My Google Chrome extension: browsing bookmarks made easy

  15. #15
    SitePoint Wizard bronze trophy Jeff Mott's Avatar
    Join Date
    Jul 2009
    Posts
    1,277
    Mentioned
    18 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by ScallioXTX View Post
    MultiViews
    Ahh, yes! I think that would explain all the strangness we've been seeing.
    "First make it work. Then make it better."

  16. #16
    Certified Ethical Hacker silver trophybronze trophy dklynn's Avatar
    Join Date
    Feb 2002
    Location
    Auckland
    Posts
    14,656
    Mentioned
    19 Post(s)
    Tagged
    3 Thread(s)
    Rémon,

    Good catch! MultiViews is one of those hidden traps that people can find themselves buried in and I agree that there is no logical reason to ever have it enabled.

    Regards,

    DK
    David K. Lynn - Data Koncepts is a long-time WebHostingBuzz (US/UK)
    Client and (unpaid) WHB Ambassador
    mod_rewrite Tutorial Article (setup, config, test & write
    mod_rewrite regex w/sample code) and Code Generator


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •