Hide path to image - .htaccess

I have
<img src="/wp-content/themes/test/folder/7.jpg">
I want to hide 'folder' and show another path:
<img src="/wp-content/themes/test/images/7.jpg">
I tried in .htaccess:
RewriteEngine on
RewriteRule ^images/([^/]+)$ folder/$1 [L]
But this doesn't work

You missed wp-content/themes/test/ in rewrite path. Test example link: your-domain.com/wp-content/themes/test/images/7.jpg should load file from /wp-content/themes/test/folder/7.jpg
RewriteEngine On
RewriteRule ^wp-content\/themes\/test\/images\/(.*)$ /wp-content/themes/test/folder/$1 [L]

Related

htaccess - Load css, js, images

I write htaccess with code:
RewriteEngine On
RewriteBase /MVC_PHP_Basic
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^/]*)$ index.php?link=$1 [L]
RewriteRule ^([^/]*)/([^/]*)$ index.php?link=$1&action=$2 [L]
RewriteRule ^([^/]*)/([^/]*)/([^/]*)$ index.php?link=$1&id=$2&action=$3 [L]
And it works and My css,js, image is loaded with url localhost/users but is not load with url localhost/users/detail.
Errors: can't load file css,js.
I know this error is due to path of css,js file because i use:
<link rel="stylesheet" type="text/css" href="assets/css/bootstrap-grid.min.css">
When url is "localhost/users", href is "localhost/assets/css/bootstrap-grid.min.css" (right).
And when url is "localhost/users/detail", href is "localhost/users/assets/css/bootstrap-grid.min.css" (wrong).
Please tell me how to fix (I don't want to use "absolute path").
Try to put / like this "/assets/css/bootstrap-grid.min.css" and place your asset folder on the root folder, or you will have to use like this "/users/assets/css/bootstrap-grid.min.css"

htaccess - read image from own server if external image not found

I try some code examples from stackoverflow, but nothing seems to work.
So I have <img src="http://external-url.com/image.png" /> and I want to show not-found.png from my server if http://external-url.com/image.png doesn't exists.
Can I do that ?
You can use this rule in your site root .htaccess:
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule \.(png|jpe?g|tiff|gif)$ /path/to/not-found.png [L,NC]
Change /path/to/not-found.png to your actual path of not-found.png.

how to Rewrite Single Page url in .htaccess

I need to rewrite only 1 specific URL
from
http://www.domainname.com/index.php?route=payment/axis/callback
to
http://www.domainname.com/payment/axis/callback
I tried these two from stack overflow, I don't know why its not working
1st one :
RewriteRule ^([A-Za-z0-9-]+)/?$ index.php?route=payment/axis/callback [NC,L]
2nd one :
RewriteRule ^index.php?route=payment/axis/callback payment/axis/callback [L]
Try this:
4) Rewriting yoursite.com/user.php?username=xyz to yoursite.com/xyz
Have you checked zorpia.com.If you type http://zorpia.com/roshanbh233 in browser you can see my profile over there. If you want to do the same kind of redirection i.e http://yoursite.com/xyz to http://yoursite.com/user.php?username=xyz then you can add the following code to the .htaccess file.
RewriteEngine On
RewriteRule ^([a-zA-Z0-9_-]+)$ user.php?username=$1
RewriteRule ^([a-zA-Z0-9_-]+)/$ user.php?username=$1
See the full page here.
Hope it helps!
I wouldn't use .htaccess with RewriteRule, since there are often problems with it. A simple workaround (with PHP redirect):
<?php
if($_GET['route'] == 'payment/axis/callback') {
header("Location: http://www.domainname.com/payment/axis/callback");
}
?>
You can either use h0ch5tr4355's workaround or you can try this:
RewriteEngine on
RewriteCond %{QUERY_STRING} ^route=payment/axis/callback$
RewriteCond %{SCRIPT_FILENAME} index.php
RewriteRule (.*) /payment/axis/callback [NC,QSD]
If you instead of a rewrite would like it to redirect to the new url you can add R=301 to the flags of the RewriteRule.

How to change URL of opencart project using htaccess?

I have a issue of URL of opencart project.
I installed oepncart project but it's URL is:
http://www.exmaple.com/opencart/upload
But i want to display it like:
http://www.exmple.com/demo using .htaccess
How can i change it?
Any one help please.
Try adding this in the htaccess file in your document root:
RewriteEngine On
RewriteRule ^demo$ /opencart/upload [L]
I think You'll need to modify the RewriteBase to be pointing to Your subdirectory from the document root:
RewriteEngine On # Already in there
RewriteBase /opencart/upload/ # Already there but with value / only
and then of course use a rewrite rule:
RewriteRule ^demo$ /opencart/upload [QSA] # Add this before the next line that is already there
RewriteRule ^([^?]*) index.php?_route_=$1 [L,QSA]

htaccess : rewrite urls

please help to rewrite Urls from
http://www.site.com/index.php?cat=catname
and
http://www.site.com/index.php?id=productname
to be like this
http://www.site.com/catname
and
http://www.site.com/productname
i think it will require php check if the page is cat work with it as cat
or its product work with it as product
in .htaccess file:
RewriteEngine On
RewriteRule ^([0-9a-z\-\_]+)?$ /index.php?id=$1 [L,QSA,NC]
category/product check must be done in index.php...
Or you can add extra slug
RewriteRule ^(category)/([0-9a-z\-\_]+)?$ /index.php?category=$1 [L,QSA,NC]
RewriteRule ^(product)/([0-9a-z\-\_]+)?$ /index.php?product=$1 [L,QSA,NC]
but url will look like http://site.com/category/catname
http://www.site.com/catname and http://www.site.com/productname
The problem with that scheme is that you can't tell whether it's a catalog name or a product name by the URL. As a result, you'll probably want something like this:
http://www.site.com/Catalog/catname and http://www.site.com/Product/productname
Which can then be implemented in a .htaccess file with the following rules:
RewriteEngine On
RewriteRule ^Catalog/(.+)$ /index.php?cat=$1 [L]
RewriteRule ^Product/(.+)$ /index.php?id=$1 [L]

Resources