I have links like this - http://example.com/index.php?q=about and I want to make them look like this - http://example.com/about
Currently I am using the Rewrite Rules
VirtualHost {
* {
Pattern = .*
RewriteRules {
dirindex {
pattern = (.*)/$
to = index.php/$1
qsa = true
}
}
}
}
If I visit http://example.com/about I am getting a 404 File Not Found
I am doing this for Drupal. Guidelines for clean urls : https://drupal.org/getting-started/clean-urls
The issue can be resolved using the VirtualHost, but the server module of HHVM is depreciated now, and you are encouraged to use fastcgi over apache/nginx. I will put an answer for VirtualHost, but if needed, can update with an nginx alternative.
First, make sure that your SourceRoot is correct:
Server {
Port = 9000
SourceRoot = /home/myuser/www
DefaultDocument = index.php
}
Now, for the rule, this should potentially work:
VirtualHost {
* {
Pattern = .*
RewriteRules {
* {
pattern = (.*)$
to = index.php/$1
qsa = true
}
}
}
}
If you want the query to work exactly as you are intending it to, replace the inner pattern with this:
* {
pattern = /(.*)
to = index.php?q=$1
qsa = true
}
I have tested these both, and they work well. If you are still facing an issue, the issue may be potentially with your setup. Make sure you enable Error and Access logging .
Related
I'm working on switching OpenAPI v2 to Open API 3, we'll be using MicroProfile 2.0 with Projects as the plugin that will generate the OAS from the code.
Now, we have different headers that are needed as a kind of authorization. I know I can put them on each resource, that seems just a lot of repetition, so I thought it was a good idea to put in the JaxRSConfiguration file as a #SecurityScheme and add them as security to the #OpenApiDefinition.
#OpenAPIDefinition(
info = #Info(
...
)
),
security = {
#SecurityRequirement(name = Header1),
#SecurityRequirement(name = Header2)
},
components = #Components(
securitySchemes = {
#SecurityScheme( apiKeyName = Header1 ... ) ,
#SecurityScheme( apiKeyName = Header2 ....)
}),
...
)
This is working, however it generates an OR, while it should be an AND (without the - )
security:
- Header1: []
- Header2: []
I thought I could use #SecurityRequirementsSet inside security in the #OpenApiDefinition, but unfortunately this is not allowed. I know I can use it on each call or on top of the class of the different calls but as this is still a sort of repetition, I would prefer to have it as a general authentication security.
Does anybody know how I can achieve this ?
I'm trying to remove some parameters using nginx return 301.
For example I want URLs redirected like this:
https://www.example.com/one?wanted=1&unwanted1=1 -> https://www.example.com/one?wanted=1
https://www.example.com/one?unwanted1=1 -> https://www.example.com/one
https://www.example.com/one?unwanted1=1&unwanted2=2&unwanted3=3 -> https://www.example.com/one
...and so on
I did some experiments with this code (note it uses rewrite instead of return):
if ($request_uri ~ "([^\?]*)\?(.*)unwanted=([^&]*)&?(.*)") {
set $args $2$4;
rewrite "^" $scheme://$host$uri permanent;
}
This works well when only one of the unwanted parameters are present.
I tried to repeat it for each parameter but now it doesn't work in an optimum way as it does multiple redirects and does not clean up the "&" when it is no longer needed (only one arg left).
...moreover - I would prefer to use return 301 instead of rewrite as I understand it would be the preferred way in these kind of situations.
Tried to adapt the last line to return 301 but it didn't work out for me.
Any ideas how I can correctly accomplish this?
To remove multiple unwanted arguments in an indeterminate order, you will need to use some form of recursion. Your question contains an example that uses an external redirection loop, but suffers from undesired edge cases.
The edge cases of leaving trailing ? and & can be cleared up using multiple if...return blocks.
For example:
if ($args ~ ^(?:unwanted1|unwanted2)=[^&]*$ ) {
return 301 $uri;
}
if ($args ~ ^(?:unwanted1|unwanted2)=[^&]*(?:&(.*))?$ ) {
return 301 $uri?$1;
}
if ($args ~ ^(.*)&(?:unwanted1|unwanted2)=[^&]*(&.*)?$ ) {
return 301 $uri?$1$2;
}
The above works by treating the two cases when a trailing ? or trailing & occurs, separately with a specially crafted return statement.
The above works by using an external redirection loop.
nginx can also perform internal redirection, and one method to achieve this is to use a rewrite...last from within a location block.
The restriction in this case would be to find the location block which will process the set of URIs that are affected by the unwanted arguments. In the example below, I use the location / block, but your requirements will be affected by the other location blocks within your configuration and the set of URIs affected.
Although you have clearly had success with assigning to the internal $args variable, my answer avoids that technique.
The following example reimplements the previous example using rewrite...last and adds a forth if block to perform the actual return 301.
location / {
if ($args ~ ^(?:unwanted1|unwanted2)=[^&]*$ ) {
rewrite ^ $uri? last;
}
if ($args ~ ^(?:unwanted1|unwanted2)=[^&]*(?:&(.*))?$ ) {
rewrite ^ $uri?$1? last;
}
if ($args ~ ^(.*)&(?:unwanted1|unwanted2)=[^&]*(&.*)?$ ) {
rewrite ^ $uri?$1$2? last;
}
if ($request_uri ~ \?(.*&)?(unwanted1|unwanted2)= ) {
return 301 $uri$is_args$args;
}
try_files $uri $uri/ =404;
}
Note that the example uses only permitted statements within the if blocks as indicated in this document.
I tried to search how i can change the web editor for my Xtext project. But it seems there is missing some documentation.
My question is how can I change the default web editor ace to my prefered editor orion ?
you need to do two things
adapt the workflow to use orion webSupport = { framework = "Orion"} (best done before first generation since generate once files will not be overriden)
since there is no webjar for orion you need to download/unpack it manually and or separately depending on your build system.
you may have a look at the Yeoman generator-xtext (https://github.com/itemis/generator-xtext) which allows you to create a gradle + xtext + web + orion project.
Workflow {
component = XtextGenerator {
...
language = StandardLanguage {
name = "org.xtext.example.mydsl.MyDsl"
fileExtensions = "mydsl"
serializer = {
generateStub = false
}
validator = {
// composedCheck = "org.eclipse.xtext.validation.NamesAreUniqueValidator"
}
webSupport = {
framework = "Orion"
}
}
}
}
I am writing an app where I would like to set the ACL for a created object to allow for public writing (there is an issue where deleting the object, which is what I want to do, can only be done if public write is set to true). I have seen several similar questions that have been answered like:
let acl = PFACL()
acl.setPublicReadAccess(true)
acl.setPublicWriteAccess(true)
yourObject.ACL = acl
However, the .setPublicWritAccess(bool) no longer seems to be the correct syntax. I tried to do it similarly with:
acl.setWriteAccess(true, for: "Public")
but this did not work. Does anyone know how to do this appropriately?
From Parse's documentation it seems that publicWriteAccess and publicReadAccess are instance properties. So, this should work:
let acl = PFACL()
acl.publicReadAccess = true
acl.publicWriteAccess = true
yourObject.ACL = acl
See more details here.
As of Parse iOS SDK 1.14.3:
let acl = PFACL()
acl.getPublicReadAccess = true
acl.getPublicWriteAccess = true
object.ACL = acl
Zend Route issue.
Normally it works fine.
http://www.example.com/course-details/1/Physics-Newtons-Law
But if I type in an extra slash in the url, the noauthAction of my Error controller gets called.
Example of URL's that are not working.
http://www.example.com/course-details//1/Physics-Newtons-Law
http://www.example.com/course-details/1//Physics-Newtons-Law
Is there something I need to set in the route definition to allow extra slashes?
Routing in application.ini
resources.router.routes.viewcourse.route = "/course-details/:course_id/:title"
resources.router.routes.viewcourse.defaults.controller = course
resources.router.routes.viewcourse.defaults.action = view
resources.router.routes.viewcourse.defaults.title =
resources.router.routes.viewcourse.reqs.course_id = "\d+"
You could use a controller plugin to fix common URL typos.
/**
* Fix common typos in URLs before the request
* is evaluated against the defined routes.
*/
class YourNamespace_Controller_Plugin_UrlTypoFixer
extends Zend_Controller_Plugin_Abstract
{
public function routeStartup($request)
{
// Correct consecutive slashes in the URL.
$uri = $request->getRequestUri();
$correctedUri = preg_replace('/\/{2,}/', '/', $uri);
if ($uri != $correctedUri) {
$request->setRequestUri($correctedUri);
}
}
}
And then register the plugin in your ini file.
resources.frontController.plugins.UrlTypoFixer = "YourNamespace_Controller_Plugin_UrlTypoFixer"