Htaccess to reduce false long path - .htaccess

There are long and false paths that work in my website, like
example.com/contact/img/img/img/img/img/img/img/file.php
Is it possible to make a htaccess which detects those random multiple '/img/' directories and redirect these paths to the index file?

Related

Exclude directories using python dirsync module

I want to sync two different directories using the dirsync module, but exclude some specific folders.
In the documentation (https://pypi.org/project/dirsync/) it says the exclude need to be a regex pattern but I cant quite make it work.
For example, lets say we have these directories
c:\folder1\folder2
c:\folder1\folder3
d:\folder1\
I want to sync c:\folder1\ with d:\folder1\ and exclude folder3, so basically the folder c:\folder1\folder2 will be copied and created in d:\
from dirsync import sync
src = r'c:\folder1'
dst = r'd:\folder1'
sync(src, dst, 'diff', exclude='^folder3')
this won't work and I can't quite understand why.
The exclude option expects a list of regexp:
exclude=['^folder3']

How do I get all files from a SharePoint URL path which has shared%20Documents in its path?

I am trying to fetch all files from a folder in SharePoint. I am looking for all file stored under "Shared%20Ducuments" path.
I am doing a GET request for an URL in Postman: https://{server_name}/sites/{sub_site}/_api/web/GetFolderByServerRelativeUrl('/Shared%20Documents')/Files
But it says:
<m:code>-2147024809, System.ArgumentException</m:code>
<m:message xml:lang="en-US">Server relative urls must start with SPWeb.ServerRelativeUrl</m:message>
My URL path for my SharePoint folder is :
https://{server_name}/sites/{sub_site}/Shared%20Documents/Forms/AllItems.aspx?AD={some extra long random mix of characters at the end}
Try to use this endpoint, prepend /sites/sub_site in GetFolderByRelativeUrl function:
_api/web/GetFolderByServerRelativeUrl('/sites/sub_sitename/Shared%20Documents')/Files

I have a URL, want to re-writing old url to new one

I have a URL, looking below:
www.abc.com/postblog.php?url=xyz
I just want to remove [ postblog.php?url= ]. How i do this. i want my new url look like this:
www.abc.com/xyz
or
www.abc.com/blog/xyz
I am using a windows server, and i am applying both type of file web.config & .htaccess . Which one is worked and how i implement this url formation.
Check this:
https://httpd.apache.org/docs/current/howto/htaccess.html
*In general, you should only use .htaccess files when you don't have access to the main server configuration file.

Isapi_rewrite 3: Redirect all non-extension requests to special file handler

I started a new site. In my .htaccess file I thought it would be a simple matter of taking any request that didn't explicitly have a file extension in the request and rewrite to a specific file. So, for example, if the request was:
http://whatever.com/styles.css
or
http://whatever.com/funnyCats.gif
or
http://whatever.com/index.htm
...the rewrite would not apply. However, if I had a request like:
http://whatever.com/funnyCats (anything without a '.')
... I'd reroute to a special handler file. I thought that should be a simple matter of:
RewriteEngine on
# anything without a period in it is not rewritten; got a period? done as is
RewriteRule ^/[^\.]*$ dynamicActionTimeByJerryBruckheimer.php?action=$1 [I]
However, while requests with '.' are served, as expected, dynamicActionTimeByJerryBruckheimer.php is never called when '/funnyCats', 'lolololol', or anything else is requested. I get the generic IIS 404 error.
What am I doing wrong?

Best practice for making code portable for domains, subdomains or directores

I recently coded something where it wasn't known if the end code would reside in a subdomain (http://user.domain.com/) or in a subdomain (http://domain.com/user), and I was lost as to the best practice for these unknown scenarios. I could thinks of a couple:
Use absolute paths (/css/styles.css) and modrewrite if it ends up being /user
Have a settings file and declare a variable with the path (<? php echo $domain . "/css/styles" ?>)
Use relative paths (../css/styles.css).
What is the best way to handle this?
If there is any question about where something might be deployed, I would avoid absolute paths whenever possible, and if you must use them, make sure to construct them using the data in the $_SERVER superglobal. The value $_SERVER['PHP_SELF'] will contain the path and filename to the currently executing script, and you can then extract the path using something like:
$path = dirname($_SERVER['PHP_SELF']);
Likewise, the value $_SERVER['HTTP_HOST'] will contain the current host, and from those two together you can build the path to wherever you are. If you're using HTTPS you may also need to check the protocol in $_SERVER['HTTPS'].
With that said, it is still best to use relative paths and a simple file and directory structure whenever possible, since it makes everything more portable and easier to read. If, as in your example, you find yourself doing a lot of ../css/styles.css then you may want to reconsider how things are structured.
Mix of 2 and 3. Use paths relative to a set variable.

Resources