Redirect to same named page in directory structure before path changes - redirect

Well, say I have a number of html pages in my web. The case is that I´m doing changes sometimes in the directory structure, so when anybody try to access to a determinated URL, it's possible that such URL does not exit. The files names don't change but so do the paths.
As far as I now, the server takes the user to a "404" page that can be customized. Is possible to customize the page in this way?:
The user tries oneweb.com/oldpath/page.html; which does not exist.
A 404 customized page is launched
404 page runs an script IS THIS POSSIBLE?
The script is given the name of the file WHERE IS STORED SUCH NAME?
The script search the entire directory structure to find page.html HOW TO ACCESS TO THE STRUCTURE
The file is found and the new URL is stored: oneweb.com/newpath/page.html
a link appears showing the new URL
Maybe this process is relatively common and I can find some related code or tutorial?

Are you using Apache? Linux?
Add a 404 handler
ErrorDocument 404 /404.php
Then use 404.php to parse the url. This simple example just grabs everything after the last / in the URI so http://example.com/foo/bar/page.html would put page.html in $url:
$url = end(explode('/', $_SERVER['REQUEST_URI']));
Then use one of the comment example functions in http://php.net/manual/en/function.readdir.php to search your directory and find the file.
Then do a header 301 redirect
header ('HTTP/1.1 301 Moved Permanently');
header ('Location: http://example.com/' . $file_path);

Related

How to use the keyword "location" in the URL parameter in AWS Amplify

I am currently working on a 1 page HTML app that uses URL parameters to do an API call. the URL parameters are set and used in QR codes so its necessary that they are able to change dynamically. A example URL would be something like app.com/index.html/?environment=demo&location=Kiosk
I currently have this app deployed in AWS Amplify, but I cant get other keywords to chain together. I have the following redirects in place:
These redirects make sure that every URL parameter I pass in the link works EXCEPT some keywords like the "location" keyword, next to some others. Using this keyword as a URL param gives a 502 server error, or if the redirects are not used an access denied error.
does anyone know how to get the location keyword to work? Thanks in advance!
You should be able to use a single rule that will forward everything to index.html EXCEPT urls with a "file extension" from the list below. That lets all your links work, but assets like images, fonts, code will pass through.
Doc for: Using Redirects - Single Page Apps
</^[^.]+$|\.(?!(css|gif|ico|jpg|js|png|txt|svg|woff|woff2|ttf|map|json)$)([^.]+$)/>

Angular developers need a path to call for the content from aem page

I generated the json file and gave the path /bin//filename.json . I am able to see the json file in author mode but not in publish. Our aem ops team says they cannot make bin as public. Tried to change the path, using js generated the json path file now at path /content//***/filename.json which I am able to see in author mode but not in publish.
My question is is there any other way that I can try . Please if any other ideas do comment.
Thank you.
Or just simple: Angular get content of page by call .infinity.json
Examp:
Your page is: /mysite/en/home.html
We change to : /mysite/en/home.infinity.json
For more detail: https://forums.adobe.com/thread/2337725
Good luck
We open using url under /bin/.. for SlingServlet
First create a slingSevlet
#SlingServlet(paths="/bin/filename.json", methods = "GET", metatype=true)
Then check the filter and make sure that /bin/filename.json accepts GET requests:
curl 'http://localhost:4502/system/console/configMgr'
Search for 'Apache Sling Referrer Filter'
Check the configuration

How facebook like websites is able to load the profile, instead of a directory when a request like facebook.com/profile/username is recieved?

When the facebook.com/profile/{username} is requested how is server able to load page with data corresponding to that user, instead of navigating to a directory named in that {username}, and possibly showing a 404 error ?
It's achieved typically using a pattern called "front controller", where all requests are handled by the same file (let's say index.php, talking specifically about PHP now). So all URLs are like this:
facebook.com/index.php/profile/abc
facebook.com/index.php/account
That file serves as the bootstrap for the application, reading extra parameters (anything after index.php) and dispatching requests to the appropriate handlers/controllers.
Then there's multiple ways you can get rid of that ugly index.php, depending on how you configure your web server (loads of questions here about that subject: htaccess remove index.php from url as an example).
Read more about it here: https://en.m.wikipedia.org/wiki/Front_controller

how to use onclick with href on cgi perl

I do have a list of files on page and next each file there is a link says delete, simply user by clicking the delete link it passes the file name on to the function on the same script then it deletes the file from server and it says on the same page, any idea?
#some other stuff goes here such list of files
print "<TD><a onclick='deleteFile()' href='#'>delete</a> </td>";
sub deleteFile()
{
unlink ($file);
}
I also tried pure cgi perl and when I click delete link it prints error "Internal Error" but when I look for the file to see if it has been delete or not then the file actually deleted so there is no permission issue here else it wouldn't delete or unlink the file, here is what changed to:
print "<a href='../cgi-bin/deleteFile.cgi?param1=$dir&param2=$file'>delete</a>";
here what I have in deleteFile.cgi I get both param1 & 2 and use unlike like below
unlink($location);
You really haven't tried hard enough to find your own solution here. I will give you some pointers ...
The onclick attribute in the HTML will trigger Javascript to be run in the browser (there are better ways to make a click event run Javascript code).
None of the Perl code in your CGI script will run unless the browser sends a request to the CGI script on the server. Things that could generate a request include:
the user clicking a link with an href that points to the CGI script (perhaps with the file pathname in a querystring parameter)
the user clicking a submit button in a form with an action that points to the CGI script (perhaps with the file pathname in a hidden form field)
some Javascript code in the browser that issues an AJAX request to the CGI script (with the file pathname as a POST parameter)
Clicking a link would result in a GET request - it is generally considered bad practice to run code that changes the state of the server (e.g.: deleting a file) is response to a GET request.
A form submission or an AJAX request can cause a POST request. You could even explicitly use a DELETE request via AJAX. These are more appropriate request methods to use for mutating server state.
Even when you get your code working, it will only be able to delete files in directories that the web server has write access to. Web servers are not generally configured with write access to any directories by default.
The problem was after deleting there was no redirect so after adding redirect page then it worked like a charm..
unlink glob ($file);
print redirect(-url=>'http://main.cgi');
thanks

Drupal 7 some non-existing URLs are not Redirecting to 404?

In Drupal 7, some of (non-existing) URLs are not redirecting to 404 or any error page it should. Instead, it still remains showing its Top Parent Folder. For example like:
www.mywebsite.com/items/aaaaaaaaaaaaa
www.mywebsite.com/items/bbbbbbbbbbbbbbbbbb
Every WRONG URLs under /items/ i put like above, are showing the Page of its parent:
www.mywebsite.com/items instead of get redirected to 404
I don't want its parent to be shown if there is no page really.
But the strange thing is, it is NOT happening on every patterns. I mean, another different parents like:
www.mywebsite.com/users/aaaaaaaaaaaaa
www.mywebsite.com/users/bbbbbbbbbbbbbbbbb
For the wrong url typed-in under this /users/ parent path, it is CORRECTLY redirecting to the 404 page.
What is it please?
If I understand your question correctly, it's not a problem at all.
That's because how your/contributed/core modules hooks Drupal menu system.
If a menu item (menu router item to be specific. Think about a path like "admin/config/development/performance") has no "%" sign in it, menu callback function will be executed.
For an example, if a module registers "items" path example.com/items path would not be a 404, and the appropriate menu callback function of the menu item will be fired. That callback function can make use of further URL parts (example.com/items/123) if given.
'node' is a good example. (technically they are different menu router items though) .
Opening example.com/node will not fire a 404.
If a module registers 'items/%' , then, example.com/items will fire a 404. In other words, the second URL part is required in order to execute the menu callback function.
If the problem you are facing is related to a custom module, make sure you register the correct version of your router items. If the second URL part is required, register items/%.
You can execute a 404 by calling drupal_not_found().
Look at this, really helpfull
http://peterpetrik.com/blog/2009/11/non-existent-urls-views-2
Are you using Views for that path (/items)?
Here is an issue for Views: Prevent duplicate content (because Views returns 200 instead of 400 404)
You could create a Contextual filter to prevent this.
merlinofchaos wrote:
If you don't want this behavior, add the Global: NULL argument to Views and use the setting to validate that the argument is empty.
For Drupal 6, the module Views 404 might help.
You can configure your drupal installation to redirect to a specefic 404 page that you create..
Go to www.yoursite.com/admin/config/system/site-information and enter your 404 page .