Trying to redirect all images to .php file.
put in .htaccess this rule:
RewriteEngine On
RewriteBase /
RewriteRule ^(.*)\.(jpg|png|jpeg|gif)$ images/w/index.php?image=$1.$2 [NC,L]
it works only when file doesnt exists
for example i have uploaded file qwe.jpg to the root folder of my site.
then i go http://mysite_com/qwe.jpg - redirect doesnt work, i see my jpg file
when i go http://mysite_com/qwe1.jpg (qwe1.jpg doesnt exist) - redirect works, i see what i have wrote in images/w/index.php!
how to make it works with existed files?
Related
I need to "internally rewrite" (without any visual redirection) all URLs from an existing folder (and everything inside of it) to its index.php file, similar as what Wordpress does, the problem is, no matter what I try it, either Wordpress overrides it showing their 404 Error page, or the site breaks.
For example, rewrite all of this URLs:
https://www.example.com/folder
https://www.example.com/folder/
https://www.example.com/folder/text
https://www.example.com/folder/text/
https://www.example.com/folder/some/text
https://www.example.com/folder/some/text/
https://www.example.com/folder/some/more/text/......
Basically anything inside /folder/ or any subfolder (whether exist or not) should be internally rewrite to https://www.example.com/folder/index.php and keeping the actual Wordpress working as usual.
I've tried some examples from other sites, as well as from similar questions like:
How does RewriteBase work in .htaccess
Redirect all to index.php using htaccess
.htaccess mod_rewrite - how to exclude directory from rewrite rule
The last one, is because I thought I could exclude the whole /folder/ path from Wordpress rewrites and create an .htaccess file inside that folder to manage it that way, well, Wordpress still shows its 404 error page.
Note: "folder" is a real folder inside the root domain, so is the main .htaccess file, and the Wordpress itself. This folder contains an index.php file.
This is the original Wordpress .htaccess file as shown here:
# BEGIN WordPress
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
# END WordPress
I hope someone can help me out, thank you.
I have vhosts set up for different brands, the only thing on these is a single PDF Voucher. Is there a way I can redirect everything excluding the pdf file to this pdf file using .htaccess
eg. example.com/voucher.pdf
so if anyone goes to anywhere else
eg example.com/index.html or example.com/random/dir/voucher.pdf
It all gets redirect here :
example.com/voucher.pdf
Thanks
So I solved it - Here is my solution for anyone that needs something similar
RewriteEngine on
RewriteRule ^$ /file.pdf [R=301]
RewriteRule ^((?!file.pdf).+)$ /file.pdf [R=301,L]
This redirects from the root to the pdf file, and then it redirects everything except file.pdf to file.pdf
I have an .htaccess file defined at www.mydomain/documentation/.htaccess and am trying to redirect a number of broken links to a specific page.
The .htaccess file contains the Rewrite Rule
RewriteRule ^/?(documentation/PresentationCore~System\.Windows\.RoutedEventArgs).*$
/documentation/v4.x/SciChart_WPF_v4_SDK_User_Manual.html [R,L,NC]
Note: RewriteEngine ON has already been defined. Other rules are being applied
Now in .htaccess tester the rule is being evaluated and redirects correctly when the following URL is requested:
www.mydomain.com/documentation/PresentationCore~System.Windows.RoutedEventArgs~Handled.html
However, when the same domain is entered into the browser, I get a 404 not found for this page.
I can confirm I have uploaded .htaccess to the correct folder and cleared the server cache.
Is there anything else I need to do to get this to work?
You dont need to match the folder name if htaccess is already in that folder, try :
RewriteRule ^/?(PresentationCore~System\.Windows\.RoutedEventArgs).*$
/documentation/v4.x/SciChart_WPF_v4_SDK_User_Manual.html [R,L,NC]
I want to redirect any folder to a specific php file with the folder name as variable using htaccess, for example:
www.domain.com/subdirectory/folder1 redirects to www.domain.com/subdirectory/file.php?id=folder1
www.domain.com/subdirectory/folder2 redirects to www.domain.com/subdirectory/file.php?id=folder2
This should work if the folders have "/" at their end, for example,
www.domain.com/subdirectory/folder3/ redirects to www.domain.com/subdirectory/file.php?id=folder3
It will be better if I can put the .htaccess file in the subdirectory and get redirect rule according to it.
I created a .htaccess file with the following code while putting the file in the subdirectory:
Options +FollowSymLinks
RewriteEngine on
RewriteRule (.*)$ file.php?id=$1
but it does not work.
RewriteRule ^folder(.*)$ file.php?id=$1
use these i am not tested but it will be work.
I have an htaccess file that I want to redirect the all pages to the another folder. I am using cakephp for the site, except for this folder which I want to redirect.
"/app/webroot/" is added to the new directory so the url is /app/webroot/new/ instead of just new.
I am placing this htaccess file (below) in the "new" directory and want anything at /app/webroot/new/ to redirect to /new/ and remove the /app/webroot/ This folder is independent of cakephp and thus does not need to be processed by cake.
The code below loops and I am not sure why.
Options +FollowSymlinks
RewriteEngine On
RewriteBase /new/
# If your concerned about direct access to a particular page without the sub-dir
# you will want to add something like this
RewriteCond %{REQUEST_URI} !^/new
RewriteRule (.*) /new/$1 [R=301,L,NC]
You should NOT place the .htaccess file in /new/ but in /app/webroot/new/.