Results 1 to 8 of 8
  1. #1

    RewriteRule. Why it doesn't work?

    Hi!

    I'm trying to set up a rewriterule on my server, but it always returns the number 404 error (not found). The $1 placed on the end of the line is not working. Why?

    The rule:
    RewriteRule !^(admin|padrao|blog)/(.*) /padrao/$1\.php [L]
    <<< Please see Forum Guidelines for signature setup. >>>

  2. #2
    Try
    RewriteRule !^(admin|padrao|blog)/(.*)$ /padrao/$1\.php [L]

  3. #3
    Sorry, the one before does not work.
    RewriteRule ^((?!(admin|padrao|blog)\/)(.*))\/(.*)$ /padrao/$1\.php [L]

  4. #4
    Join Date
    Feb 2005
    Location
    Australia
    Posts
    5,849
    Quote Originally Posted by linkhost View Post
    I'm trying to set up a rewriterule on my server, but it always returns the number 404 error (not found). The $1 placed on the end of the line is not working. Why?
    Probably because your rule says that the request should not match the regexp, and then you're trying to extract the part ($1) that matches.

    This is untested but something like it should do what you want:
    Code:
    RewriteCond %{REQUEST_URI} !^(admin|padrao|blog)
    RewriteRule (.*) /padrao/$1\.php [L]
    Last edited by foobic; 02-09-2012 at 02:46 AM. Reason: Simplified
    Chris

    "Some problems are so complex that you have to be highly intelligent and well informed just to be undecided about them." - Laurence J. Peter

  5. #5
    Join Date
    Jan 2012
    Location
    Copenhagen, Denmark
    Posts
    20
    i have some different problem, first I am rewriting site to www for desktop version and then I have mobile site as well, I am rewriting to mobile, until url alias is working.
    But if inside url is rewriting from desktop to mobile like sitename*com/about to m.sitename*com/about its url alias goes very bad. something like m.sitename*com/querypage?querypage?about

    any one have any idea?

    regards
    Nyssa

  6. #6
    Quote Originally Posted by Nathan C View Post
    Sorry, the one before does not work.
    RewriteRule ^((?!(admin|padrao|blog)\/)(.*))\/(.*)$ /padrao/$1\.php [L]
    Almost perfect! There is only one problem: I always need to put a "/" on the end of the URL. Like this: www.site.com/something doesn't match. But www.site.com/something/ works
    <<< Please see Forum Guidelines for signature setup. >>>

  7. #7
    Quote Originally Posted by foobic View Post
    Probably because your rule says that the request should not match the regexp, and then you're trying to extract the part ($1) that matches.

    This is untested but something like it should do what you want:
    Code:
    RewriteCond %{REQUEST_URI} !^(admin|padrao|blog)
    RewriteRule (.*) /padrao/$1\.php [L]
    This code returns error 500
    <<< Please see Forum Guidelines for signature setup. >>>

  8. #8
    To have / at the end, insert \/ right before $.
    $ means match the end of string
    So something like

    ^[0-9]+$ would match 100, but not 100a

Similar Threads

  1. cp -f doesn't work?
    By twrs in forum Hosting Security and Technology
    Replies: 14
    Last Post: 07-20-2011, 11:13 AM
  2. Why doesn't mod_rewrite always work the same?
    By lexington in forum Programming Discussion
    Replies: 0
    Last Post: 07-01-2011, 05:46 AM
  3. My server doesn't support RewriteRule
    By SLiM_BoY in forum Hosting Security and Technology
    Replies: 1
    Last Post: 08-18-2006, 07:14 AM
  4. Why won't this code work? - RewriteCond/RewriteRule
    By MaxS in forum Programming Discussion
    Replies: 4
    Last Post: 11-11-2005, 10:16 AM

Posting Permissions

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