0
RewriteCond %{REQUEST_URI} !^/?new.php?url
RewriteRule ^/?(.+)\.?(.+)$ new.php?url=$0 [L]

its supposed to take any URL

mysite.com/someurl

and convert it to

new.php?url=someurl

however it keeps going to just new.php

gwegaweg
  • 33
  • 1
  • 5
  • Possible duplicates: http://stackoverflow.com/questions/1616719/need-a-regex-to-match-url-without-http-https-ftp, http://stackoverflow.com/questions/1616770/help-rewriting-this-url-simple-but-not-working – Gumbo Oct 24 '09 at 08:02

3 Answers3

2

You need to escape the second question mark in the first line so it matches a literal question mark:

RewriteCond %{REQUEST_URI} !^/?new.php\?url

Also you are not using the parenthesized groups on the second line. $0 is okay, or you may want $1 instead. If you use $0 you could simplify it a bunch:

RewriteRule ^.*$ new.php?url=$0 [L]

Or on the other hand if you're breaking apart the URL for a reason I would suggest some fixup. You're not matching the file name and extension exactly right. A little more complex regex like this would probably do you better:

RewriteRule ^/?(.*?)(?:\.([^.]*))?$ new.php?path=$1&extension=$2 [L]

Explanation:

  1. (.*?) matches the directory and file name. The ? means match non-greedily, so stop as soon as the next part matches. The parentheses cause it to be captured and stored in $1.

  2. (?:\.([^.]*))? matches the file extension. ?: turns says to not capture the outer set of parentheses, so the dot is not captured in $2. ([^.]*) matches the extension and ensures that it does not contain a dot. The final ? makes the file extension part optional, just cause not all URLs have file extensions. Thus there will only be a $2 if there is a file extension.

John Kugelman
  • 349,597
  • 67
  • 533
  • 578
0

The first back-reference is $1 not $0 AFAIK. If that doesn't do it try specifying [QSA] as well, though I doubt that's it.

RewriteCond %{REQUEST_URI} !^/?new.php?url
RewriteRule ^/?(.+)\.?(.+)$ new.php?url=$1 [L]
meder omuraliev
  • 183,342
  • 71
  • 393
  • 434
0

The first back reference should be $1 instead of $0.

RewriteCond %{REQUEST_URI} !^/?new.php?url
RewriteRule ^/?(.+)\.?(.+)$ new.php?url=$1 [L]

It also depends on what other lines of code you have in the file. It's also possible to mess up rewrites if you have another code that conflicts with it.

homework
  • 4,987
  • 11
  • 40
  • 50