I currently have trouble figuring out why my url rewrite is not persisting the request (get) parameters.
This is a sample url:
http://localhost:8888/testwelt/allgemein?test=1234
And this is my rewrite inside the lighttpd.conf:
url.rewrite-once = (
"^(/testwelt/(?!(favicon.ico$|sitemap.xml$|js/|pages/)).*)(\?|$)(.*)" => "/testwelt/index.php?url=$1&$3"
)
A var_dump of my $_GET reveals this:
array(1) { ["url"]=> string(39) "/testwelt/allgemein?test=1234" }
I am not too fit when it comes to url-rewriting. What am i doing wrong?
Thank you!
I fixed my problem with something like this:
url.rewrite-once = (
"^/testwelt/(sitemap.xml$|favicon\.ico$|php/|css/|js/).*" => "$0",
"^/testwelt/([^?]*)(?:\?(.*))?" => "/testwelt/index.php?url=$1&$2"
)
Little explanation:
The first rule "prevents" a rewrite for specific files/folders by redirecting to the URL match.
The second rule matches until a "?" character which indicates the url parameters. Then it matches the URL parameters and adds them to the rewritten url.
Related
I have the following mod_rewrite code for lighttpd, but it does not properly foreward the user:
$SERVER["socket"] == ":3041" {
server.document-root = server_root + "/paste"
url.rewrite-once = ( "^/([^/\.]+)/?$" => "?page=paste&id=$1")
}
It should turn the url domain.com/H839jec into domain.com/index.php?page=paste&id=H839jec however it is not doing that, instead it is redirecting everything to domain.com. I dont know much about mod_rewrite and would appreciate some input on why it is doing this.
Use the following :
url.rewrite-once = ("^/(.*)$" => "/?page=paste&id=$1")
I don't know the exact issue in your code, but first the regex looks unnecessarily complicated and may not match what you expected it to match, and second you're redirecting to a query string where as I would expect you still need to redirect to a valid path before the query string, that's why I redirect to /?page... instead of just ?page....
If I want to construct this url: /categories/5/update/?hidden=1 how could I pass both {id} param and hidden param (as GET) ?
My route is:
Route::get('categories/{id}/update', 'CategoryController#update');
I don't want to make a form and put it as POST because I have a number of buttons which simply hides/shows/removes a category and dont want to make a lot of forms for simple actions, although it has nothing to do with the question
I'm just a little bit confused, because it seems like action('CategoryController#update', [$id, 'hidden' => 1]) constructs the right URL but I got no idea how it's distinguished that the first one ($id) must be in URL and the second is a GET param
You may also try this to generate the URL:
$action = action('CategoryController#update', [id => $id]) . '?hidden=1';
Also, query string could be passed with any route even without mentioning about that in Route declaration.
how to write url address with parameter like this
www.example.com/param1/var1/param2/var2
and next get it with :
$param1 = Mage::app()->getRequest()->getParam('param1');
$param2 = Mage::app()->getRequest()->getParam('param2');
The default router expects that the first 3 parts in the url to be module, controller, action and then the rest of the parameters are treated as GET parameters.
You can generates such an url like this:
Mage::getUrl('module/controller/action', array('param1'=>'var1', 'param2'=>'var2'))
check here for full deails on this :
you need to do something like this.
http://www.magentocommerce.com/wiki/5_-_modules_and_development/reference/geturl_function_parameters
Mage::getUrl('cms/page/view', array('id' => 1));
// http://www.example.com/cms/page/view/id/1
Also your code to get these values from url is correct.
Following url is working fine:
http://www.domain.com/address
but when I pass any querystring like:
http://www.domain.com/address?back=order-opc.php?step=1
It shows 404 page
my rewrite:
"^/address" => "/address.php",
i have tried so many different rewrite nothing seems to work...
how should i rewrite ?
You should take in count the rest of the query string in your rule.
"^/address(\?.*)?" => "/address.php$1",
Your query string should be:
http://www.domain.com/address/?back=order-opc.php?step=1
Note the slash / as /address means /address/index.php or /address/index.html ( or whatever is your default document )
I have a url such as:
http://www.relevantmagazine.com/life/relationship/blog/23317-pursuing-singleness
And would like to extract just relevantmagazine from it.
Currently I have:
#urlroot = URI.parse(#link.url).host
But it returns www.relevantmagazine.com can anyone help me?
Using a gem for this might be overkill, but anyway: There's a handy gem called domainatrix that can extract the sitename for your while dealing with things like two element top-level domains and more.
url = Domainatrix.parse("http://www.pauldix.net")
url.url # => "http://www.pauldix.net" (the original url)
url.public_suffix # => "net"
url.domain # => "pauldix"
url.canonical # => "net.pauldix"
url = Domainatrix.parse("http://foo.bar.pauldix.co.uk/asdf.html?q=arg")
url.public_suffix # => "co.uk"
url.domain # => "pauldix"
url.subdomain # => "foo.bar"
url.path # => "/asdf.html?q=arg"
url.canonical # => "uk.co.pauldix.bar.foo/asdf.html?q=arg"
how about
#urlroot = URI.parse(#link.url).host.gsub("www.", "").split(".")[0]
Try this regular expression:
regex = %r{http://[w]*[\.]*[^/|$]*}
If you had the following url strings, it gives the following:
url = 'http://www.google.com/?q=blah'
url.scan(regex) => ["http://www.google.com"]
url = 'http://google.com/?q=blah'
url.scan(regex) => ["http://google.com"]
url = 'http://google.com'
url.scan(regex) => ["http://google.com"]
url = 'http://foo.bar.pauldix.co.uk/asdf.html?q=arg'
url.scan(regex) => ["http://foo.bar.pauldix.co.uk"]
It's not perfect, but it will strip out everything but the prefix and the host name. You can then easily clean up the prefix with some other code knowing now you only need to look for an http:// or http://www. at the beginning of the string. Another thought is you may need to tweak the regex I gave you a little if you are also going to parse https://. I hope this helps you get started!
Edit:
I reread the question, and realized my answer doesn't really do what you asked. I suppose it might be helpful to know if you know if the urls you're parsing will have a set format like always have the www. If it does, you could use a regular expression that extracts everything between the first and second period in the url. If not, perhaps you could tweak my regex so that it's everything between the / or www. and the first period. That might be the easiest way to get just the site name with none of the www. or the .com or .au.uk and such.
Revised regex:
regex = %r{http://[w]*[\.]*[^\.]*}
url = 'http://foo.bar.pauldix.co.uk/asdf.html?q=arg'
url.scan(regex) => ["http://foo"]
It'll be weird. If you use the regex stuff, you'll probably have to do it incrementally to clean up the url to extract the part you want.
Maybe you can just split it?
URI.parse(#link.url).host.split('.')[1]
Keep in mind that some registered domains may have more than one component to the registered country domain, like .co.uk or .co.jp or .com.au for example.
I found the answer inspired by tadman's answer and the answer in another question
#urlroot = URI.parse(item.url).host
#urlroot = #urlroot.start_with?('www.') ? #urlroot[4..-1] : #urlroot
#urlroot = #urlroot.split('.')[0]
First line get the host, second line gets removes the www. if they is one and third line get everything before the next dot.