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 )
Related
I am new to Laravel and working on existing code.
I want to pass some values in url in format of URL/val1/val2/val3.
Every thing is working perfect if all values with normal string or number
but if any value has special character like slash / or \ it shows errors.
eg.
working :- URL/abc/pqr/xys
but if val3 = 22/06 ;url is URL/val1/val2/22/06 error shows 404 not found
If I encoded val3 using javaScript's function encodeURIComponent()
val3=22%2F06 and url become URL/val1/val2/22%2F06 shows Object not found!
// My current route web.php is:-
Route::get('/export/{name}/{status}/{search}', 'ReportController#export')->name('export');
//routes.php
Route::get('view/{slashData?}', 'ExampleController#getData')
->where('slashData', '(.*)');
Your route accept only 3 params. But you pass four params.
Route::get('/export/{name}/{status}/{search}', 'ReportController#export')->name('export');
You must change your val3=22-06. Don't use / as value of your param.
Eg.
URL/val1/val2/22-06
You need to use regex expression for that situation:
Route::get('/export/{name}/{status}/{search}', 'ReportController#export')->name('export')->where(['search' => "[\w\/]+"]);
I have a url "http://localhost/codeigniter/index.php/manual_export/". I need to get last segment from the url which is suppose to be a id. So for example "http://localhost/codeigniter/index.php/manual_export/2". I need to get the last segment which is "2".
I tired to use following code:
$id = end($this->uri->segment_array());
This works when I don't add "2" to the url and gives me "manual_export". However when I pass the id to the url I get an error "The page you requested was not found.". I think this is to do with routing. How can I fix this error.
the other way to do it is by defining a route, it will then be converted to a param
so for example if your controller is called manual_export and the method is getrecord
in the file application/routes.php
$route['manual_export/(:any)'] = "manual_export/getrecord/$1";
in your controller manual_export
function getrecord($id){ // etc etc }
You should use:
$this->uri->segment(n);//in your case n == 2 count starts just after index.php
Docs.
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.
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....
I am using the Facebook PHP SDK in order to allow users to log in to my site using Facebook.
In my test below (assume the URL is http://mysite.com/test/fbtest.php),
<?php
require_once("facebook.php");
$fb = new Facebook(array('appId' => 'APP_ID', 'secret' => 'APP_SECRET'));
$fbuser = false;
$fbuserid = $fb->getUser();
$fblogin = $fb->getLoginUrl(array(
'redirect_uri' => "http://{$_SERVER['HTTP_HOST']}/test/fbtest.php"));
if($fbuserid)
{
try
{
$fbuser = $fb->api("/me");
print_r($fbuser);
echo "<br/>\n";
}
catch (FacebookApiException $e)
{
$fbuser = false;
$fbuserid = 0;
}
}
if(!$fbuser)
echo "FB Login\n";
?>
This seems to work as expected. However, when I add the following rewrite rule,
RewriteRule ^/FBtest/(.*)$ http://%{HTTP_HOST}/test/fbtest.php$1
Then change my login redirect to the following,
$fblogin = $fb->getLoginUrl(array(
'redirect_uri' => "http://{$_SERVER['HTTP_HOST']}/FBtest/"));
Then $fb->getUser() always returns 0. I feel that I am missing something important.
In the server side flow, your redirect_uri get’s called with the necessary values as GET parameters in the query string.
'redirect_uri' => "http://{$_SERVER['HTTP_HOST']}/FBtest/"
So with this redirect_uri, something like
http://example.com/FBtest/?state=foo&code=bar
will be called on your server.
RewriteRule ^/FBtest/(.*)$ http://%{HTTP_HOST}/test/fbtest.php$1
RewriteRules don’t examine the query string, they only look at the path component of the URL. In your case, that’s /FBtest/, nothing behind it – so the internal redirect goes to /test/fbtest.php, and the query string parameters get lost, because you didn’t say you wanted to pass them on.
Add the flag [QSA] – for “query string append” – to your RewriteRule (and remove the unnecessary (.*)) – then things should work as expected, because your fbtest.php will get the query string parameters needed for the auth process.
Finally figured this problem out. Here is the RewriteRule I need:
RewriteRule ^/FBtest/$ http://%{HTTP_HOST}/test/fbtest.php [QSA,NE]
It turns out I needed to add both the QSA and NE flags to this rule.
Much like in CBroe's answer, the QSA flag was needed for the state/code parameters added to redirect_uri (using (.*) within the RewriteRule instead doesn't catch these additional parameters).
I also needed to add the NE flag because the state/code that the Facebook authentication was adding to the redirect_uri was being escaped.
You will not be able to use any other domain other than the domain you set in your applications settings.
"be sure you are using the root domain, and not sample.com/test/ as your url settings."