PHP redirect custom variable URL - .htaccess

I want to redirect the following URL:
/folder/Some%20Variable%20File%20Name
to
/folder/some-variable-file-name
When users visit example.com/videos/Bollywood%20Movie%202016 directly.
Note: I want to redirect lots of variables and not just the above URL. The above URL is just for explanation.

Try:
Redirect "/videos/Bollywood%20movie%202016" /videos/Bollywood-movie-2016

Found solution to the problem:
<?php
$uri = $_SERVER[REQUEST_URI];
if (stripos("$uri", "%20")) {
$uri = strtolower($uri);
$uri = str_replace("%20", "-", $uri);
$uri = str_replace(" ", "-", $uri);
header("Location: $uri");
exit;
}
?>

Related

Safari Content Blocker doesn't work with URL

I need to block url and make blockerList code below
[
{
"action":{
"type":"block"
},
"trigger":{
"url-filter": ".*",
"if-top-url": ["https://m.youtube.com/watch?v=-wKiNZ-u-HA", "https://webkit.org/blog/4062/targeting-domains-with-content-blockers/"]
}
}
]
For "https://webkit.org/blog/4062/targeting-domains-with-content-blockers/" everything works well and blocked.
But for example "https://m.youtube.com/watch?v=-wKiNZ-u-HA" blocker not working.
Please help resolve the issue so that all the indicated url are blocked

Problem with setting preAuthorizedApplications in Azure app registration with Az Powershell 7.1.0

I have a problem with automating the setting of the preAuthorizedApplications for a Azure app registration from Az powershell 7.1.0. The code is making a transition to the MS Graph api's, but the syntax of the preAuthorizedApplications is not clear to me. Everything i found on the net, i tried. But nothing works and keeps erroring out.
I created a piece of test code and a test app registration:
Get-AzADApplication -ApplicationId 956afe7b-f58f-4de5-83ea-02035cc98b3f # Just to get the Types
$PreAuthPrem1 = New-Object -TypeName "Microsoft.Azure.PowerShell.Cmdlets.Resources.MSGraph.Models.ApiV10.MicrosoftGraphPreAuthorizedApplication"
$PreAuthPrem1.AppId = "1fec8e78-bce4-4aaf-ab1b-5451cc387264"
$PreAuthPrem1.DelegatedPermissionId = "d3a943ac-ea3b-4271-b750-abcd91b01162"
Update-AzADApplication -ApplicationId 956afe7b-f58f-4de5-83ea-02035cc98b3f -api #{"preAuthorizedApplications" = $PreAuthPrem1} -debug
It keep giving me the same error, what is not very helpfull:
Line |
549 | Az.MSGraph.internal\Update-AzADApplication #PSBoundParameters
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
| Property preAuthorizedApplications in payload has a value that does not match schema.
The request to MS graph is below (taken from the debug command)
DEBUG: ============================ HTTP REQUEST ============================
HTTP Method:
PATCH
Absolute Uri:
https://graph.microsoft.com/v1.0/applications/ccd14ce8-1afe-45b3-a461-777d3129399b
Headers:
x-ms-unique-id : 6
x-ms-client-request-id : cb41d352-4b67-4142-8795-9b77bf9b057a
CommandName : Az.MSGraph.internal\Update-AzADApplication
FullCommandName : Update-AzADApplication_UpdateExpanded
ParameterSetName : __AllParameterSets
User-Agent : AzurePowershell/v0.0.0,Az.MSGraph/5.2.0
Body:
{
"api": {
"preAuthorizedApplications": "{\r\n "appId": "1fec8e78-bce4-4aaf-ab1b-5451cc387264",\r\n "delegatedPermissionIds": [ "d3a943ac-ea3b-4271-b750-abcd91b01162" ]\r\n}"
}
}
I found documentation to with says it should be delegatedPermissionIds but also that is should be permissionIds. Both do not work for me
https://learn.microsoft.com/en-us/powershell/module/az.resources/update-azadapplication?view=azps-7.1.0
https://learn.microsoft.com/en-us/graph/api/resources/preauthorizedapplication?view=graph-rest-1.0
Also it tried other ways of setting the body to not include the specials characters but everything just keeps giving the same error.
Also updated the az powershell (to 7.1.0) and powershell itself (7.2.1 core)
Also tried with azure ClI
$appObjectId='956afe7b-f58f-4de5-83ea-02035cc98b3f'
az rest -m PATCH -u https://graph.microsoft.com/v1.0/applications/$appObjectId --headers Content-Type=application/json -b '{"api":{"preAuthorizedApplications":[{"appId":"1fec8e78-bce4-4aaf-ab1b-5451cc387264","permissionIds":["d3a943ac-ea3b-4271-b750-abcd91b01162"]}]}}'
Bad Request({"error":{"code":"BadRequest","message":"Unable to read JSON request payload. Please ensure Content-Type header is set and payload is of valid JSON format.","innerError":{"date":"2022-01-31T06:23:44","request-id":"2ac51323-4f9b-4da8-8ec8-1187e4b73a59","client-request-id":"2ac51323-4f9b-4da8-8ec8-1187e4b73a59"}}})
Looks like the same problem
We have tried the same in our environment as an alternate solution we can try Graph Explorer .
To do that we have to get our Oauth2Permissions id from manifest or by running the below code we can get :
az ad app show --id $appId --query "oauth2Permissions[].id"
Now we need to use graph explorer to achieve the above requirement by mention the following in our request body by using below method:
Patch : https://graph.microsoft.com/beta/applications/<appObjectId>
Request body :
{
"api": {
"preAuthorizedApplications": [
{
"appId": "authorizedappClientID",
"permissionIds": [
"oauth2PermissionId"
]
}
]
}
}
Provide the object id of the application in above given URI.
Allow the following consent > Modify permission
And check your permission ID by navigate to manifest if that is correct or not.
OUTPUT:-
For use az rest please refer this SO THREAD .
This is the code that worked in my Devops pipeline. I gave the service principle the rights and enabled access on to the token.
$Body = #"
{
"api": {
"preAuthorizedApplications": [
{
"appId": "1fec8e78-bce4-4aaf-ab1b-5451cc387264",
"permissionIds": [
"d3a943ac-ea3b-4271-b750-abcd91b01162"
]
}
]
}
}
"#
$Uri = 'https://graph.microsoft.com/beta/applications/ccd14ce8-1afe-45b3-a461-777d3129399b'
$method = 'PATCH'
$Token = (Get-AzAccessToken -ResourceTypeName MSGraph).Token
$Header = #{
Authorization = "Bearer $Token"
}
Invoke-WebRequest -Uri $Uri -Method $method -Headers $Header -ContentType 'application/json' -Body $Body

How to update excel input file directly in Azure Git repository without downloading the entire project folder to local machine

I have a java maven project (Eclipse) in Azure Git repository.
It is a test project to create data in system based on the input given in the excel.
Currently I have the entire project cloned in local machine with git, update the input excel file and push to Azure repository, before running the test.
Is there a way to push changes to the input excel file directly in repository, without downloading the entire project folder to local?
Just upload it directly ...
... naturally, it will create a commit but this is easy enough. I've made code changes before without an IDE by simply editing existing files in the repo online.
We have no method to directly open and edit an Excel file in Git repository on the web browser.
I have tried on several Git-based version control platforms (Azure Git Repos, GutHub, GitLab, Bitbucket, etc..). None of then can allow users to directly open and edit an Excel file in Git repository.
I also did not find any available extension can help to do this.
So, you need to download the Excel file to the local where the MS Office installed, then open and edit it locally.
Maybe, using the Azure DevOps Services REST / Pushes - Create
POST https://dev.azure.com/fabrikam/_apis/git/repositories/{repositoryId}/pushes?api-version=6.0
But that seems a lot of work compared to a simple script which would, every time you have modified locally your Excel file:
git add
git commit
git push
You can use REST and Powershell to update files on remote repo.... as an example:
$user = ""
$token = "<PAT>" #https://learn.microsoft.com/en-us/azure/devops/organizations/accounts/use-personal-access-tokens-to-authenticate?view=azure-devops&tabs=preview-page
$base64AuthInfo = [Convert]::ToBase64String([Text.Encoding]::ASCII.GetBytes(("{0}:{1}" -f $user,$token)))
$orgUrl = "https://dev.azure.com/<org>"
$teamProject = "TestProject"
$repoName = "Repo1"
$localFilePath = 'c:/temp/tst.xlsx'
$gitFilePath = 'testfolder/tst.xlsx'
$gitBranch = "master"
$restApiUpdateFile = "$orgUrl/$teamProject/_apis/git/repositories/$repoName/pushes?api-version=6.1-preview.2"
$restApiGetMasterRef = "$orgUrl/$teamProject/_apis/git/repositories/$repoName/refs?filter=heads/$gitBranch`&api-version=6.1-preview.1"
$fileContentToUpdate = [convert]::ToBase64String((Get-Content -path $localFilePath -Encoding byte))
function InvokeGetRequest ($GetUrl)
{
return Invoke-RestMethod -Uri $GetUrl -Method Get -ContentType "application/json" -Headers #{Authorization=("Basic {0}" -f $base64AuthInfo)}
}
function InvokePostRequest ($PostUrl, $body)
{
return Invoke-RestMethod -Uri $PostUrl -Method Post -ContentType "application/json" -Headers #{Authorization=("Basic {0}" -f $base64AuthInfo)} -Body $body
}
$updateBody = #"
{
"refUpdates": [
{
"name": "refs/heads/{gitbranchpath}",
"oldObjectId": "{mainBranchObjectId}"
}
],
"commits": [
{
"comment": "Updates file",
"changes": [
{
"changeType": "edit",
"item": {
"path": "{filePathToUpdate}"
},
"newContent": {
"content": "{newFileContentToUpdate}",
"contentType": "base64encoded"
}
}
]
}
]
}
"#
$res = InvokeGetRequest $restApiGetMasterRef
$updateBody = $updateBody.Replace("{gitbranchpath}", $gitBranch);
$updateBody = $updateBody.Replace("{mainBranchObjectId}", $res.value[0].objectId);
$updateBody = $updateBody.Replace("{filePathToUpdate}", $gitFilePath);
$updateBody = $updateBody.Replace("{newFileContentToUpdate}", $fileContentToUpdate);
InvokePostRequest $restApiUpdateFile $updateBody

Clone Azure Test Plan to new area path using powershell

I have a powershell script that clones my test plans - I am using Azure 2019 so the function is not built in. My script works, but only clones plans to the same area path. I would like to be able to clone to a new area path. For example, in the image below, under Test Plans, I want to clone 'TestPlan1.7' in MyTests\Version1.7 to 'NewTestPlan' in MyTests\Version1.8. The code I use currently creates the new test plan as it clones, but either that or manually creating a new one is an option. Also, I cannot download/ install any addons or mods to azure, so those aren't a solution for me. Thanks for any help!
Here is my current code snippet to clone. I have the variables listed in my script, but don't think they're needed for this.
EDIT: I tried your answer Sunny (and also just realized I can edit my own question to add stuff) Here is my entire code, along with the error. The variables have been changed for obvious reasons, but the structure is the same. The line number the error gave is the one that starts with 'Invoke-WebRequest'
$organization = "myOrg"
$PAT = "MyAzurePAT"
$myBaseUrl = "myAzureUrl"
$project = "myTests"
$planId = "123456"
$suiteId = "123457"
$cloneTo = "NewtestPlan"
$authorization = [Convert]::ToBase64String([System.Text.Encoding]::UTF8.GetBytes(":$PAT"))
$headers = New-Object "System.Collections.Generic.Dictionary[[String],[String]]"
$headers.Add("Accept-Charset", 'UTF-8')
$headers.Add('Content-Type','Application/Json')
$headers.Add('Authorization',"Basic $authorization")
$postParams=#"
{
"destinationTestPlan": {
"name": "$cloneTo",
"Project": {
"Name": "$project"
}
},
"options": {
"copyAncestorHierarchy": true,
"copyAllSuites": true,
"overrideParameters": {
"System.AreaPath": "myTests\Version1.8",
"System.IterationPath": "NewtestPlan"
}
},
"suiteIds": [
$suiteId
]
}
"#
$apiUrl = "$myBaseUrl/$organization/$project/_apis/test/Plans/$planId/cloneoperation?api-version=5.0-preview.2"
Invoke-WebRequest -Uri $apiUrl -Method POST -Headers $headers -Body $postParams | Select-Object -Expand StatusDescription
<#Error
Invoke-WebRequest : {"$id":"1","innerException":null,"message":"Value cannot be
null.\r\nParameter name: cloneRequestBody","typeName":"System.ArgumentNullException,
mscorlib","typeKey":"ArgumentNullException","errorCode":0,"eventId":0}
At [locationRemoved]\testPlanCloneTool.ps1:39 char:1
+ Invoke-WebRequest -Uri $apiUrl -Method POST -Headers $headers -Body $ ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: (System.Net.HttpWebRequest:HttpWebRequest) [Invoke-WebRequest], WebException
+ FullyQualifiedErrorId : WebCmdletWebResponseException,Microsoft.PowerShell.Commands.InvokeWebRequestCommand
#>
have you tried the "overrideParameters" under "options"?
$postParams=#"
{
"destinationTestPlan": {
"name": "$cloneTo",
"Project": {
"Name": "$project"
}
},
"options": {
"copyAncestorHierarchy": true,
"copyAllSuites": true,
"overrideParameters": {
"System.AreaPath": "MyTests\Version1.8",
"System.IterationPath": "NewTestPlan"
}
},
"suiteIds": [
$sourceSuiteId,
]
}
"#
MS Docs Ref: https://learn.microsoft.com/en-us/rest/api/azure/devops/test/clone%20operation/clone%20test%20plan?view=azure-devops-rest-5.0#cloneoptions

TFS Code Search/Work Rest API return 404

we are using TFS on-premise.
TFS version:
Microsoft Visual Studio Team Foundation Server
Version 16.122.27409.2 (2018).
We need to perform TFS source control (Code Search)
According to MS API documentation this the way to use TFS REST API.
Build and Release API are working, but search API return 404.
Search Code extension installed and working fine from TFS portal.
API Url:
POST: http://{DNS}:8080/tfs/{Collection}/{Project}/_apis/search/codesearchresults?api-version=4.1-preview.1
the result:
Please help, what I'm, doing wrong?
You can't just open it in a browser. You have to provide a request body, as expressed clearly in the API examples:
{
"searchText": "CodeSearchController",
"$skip": 0,
"$top": 1,
"filters": {
"Project": [
"MyFirstProject"
],
"Repository": [
"MyFirstProject"
],
"Path": [
"/"
],
"Branch": [
"master"
],
"CodeElement": [
"def",
"class"
]
},
"$orderBy": [
{
"field": "filename",
"sortOrder": "ASC"
}
],
"includeFacets": true
}
Just as Daniel said "You can't just open it in a browser. You have to provide a request body"
So you can use tools such as Postman to send the request with request body, or you can use PowerShell to call the REST API with request body.
Besides, based on my test it seems the REST API you mentioned (Code Search Results) is not apply to on-premise TFS. I tested on TFS 2018 Update2 (Version 16.131.27701.1), it always return "count": 0,.
However you can use below REST API to search code:
POST http://server:8080/tfs/DefaultCollection/{Project}/_api/_search/postCodeQuery?api-version=4.1-preview.1
Request Body:
{"searchText":"<test1>",
"scope":"Team Foundation Server",
"filters":"{\"ProjectFilters\":[\"0511ScrumTFVC\"]}",
"skipResults":0,
"takeResults":50,
"sortOptions":""
}
Below PowerShell sample for your reference:
Param(
[string]$baseurl = "http://server:8080/tfs/DefaultCollection",
[string]$projectName = "ProjectName",
[string]$user = "username",
[string]$token = "password"
)
# Base64-encodes the Personal Access Token (PAT) appropriately
$base64AuthInfo = [Convert]::ToBase64String([Text.Encoding]::ASCII.GetBytes(("{0}:{1}" -f $user,$token)))
function CreateJsonBody
{
$value = #"
{"searchText":"<test1>",
"scope":"Team Foundation Server",
"filters":"{\"ProjectFilters\":[\"ProjectName\"]}",
"skipResults":0,
"takeResults":50,
"sortOptions":""
}
"#
return $value
}
$json = CreateJsonBody
$uri = "$baseurl/$($projectName)/_api/_search/postCodeQuery?api-version=4.1-preview.1"
Write-Host $uri
$result = Invoke-RestMethod -Uri $uri -Method POST -Body $json -ContentType "application/json" -Headers #{Authorization=("Basic {0}" -f $base64AuthInfo)}
$result = $result | convertto-json
Write-host $result

Resources