I'm trying to use Stacey CMS in conjunction with retina.js for my small portfolio site. Stacey tells all images inside a project folder to be added to the page. At the same time I'd like to serve #2x hi-dpi images. If I include these in the same folder, Stacey will add both the regular image.png and image#2x.png to the page, which I want to avoid.
To solve this, I want to rewrite all images ending with #2x to have the root /retina inside the same project folder. This folder is dynamic, ie. there are many different project folders, so I would like to have one rewrite rule to work for all.
I've gotten to this point with some help from a fellow stack overflow user:
RewriteRule ^(.*)#2x(.*)$ /Retina/$1#2x$2 [L]
This however, does not refer to a subfolder of the original project folder. How do I go about referring to the correct folder?
Edit: Alternatively there may be other ways to solve this issue? Changing retina.js retina image path
I think that the problem you encounter is do to an endless redirect loop.
as your rule
RewriteRule ^(.*)#2x(.*)$ /Retina/$1#2x$2 [L]
Will try to redirect the call for the retina image uri like /image#2x.jpg but also again and again for the new url's /retina/image#2x.jpg as your rule only checks if the requested uri has the #2x string in it.
Try adding another condition to the rule that will prevent the rule to be processed for images that are in the retina folder
RewriteCond %{REQUEST_URI} !Retina
RewriteRule ^(.*)#2x(.*)$ /Retina/$1#2x$2 [L]
If the Retina folder is actually inside another folder and you have multiple Retina folders, meaning that when you call site.com/project1/image.png the retina version is in site.com/project1/retina/image#2x.png then you should try this:
RewriteCond %{REQUEST_URI} !Retina
RewriteRule ^(.*)/(.*)#2x(.*)$ /$1/Retina/$2#2x$3 [L]
in the Retina folders are inside the sub-folders, the first rewrite rule we used will have both the folder name & the image name in the variable $1, so what we should do is just break the folder name & the image name into two separate variables
Related
What I would like to do is serve up a file such as "boat-repair" and have the url read allservicemarine.com/boat-repair/electrical-system-repair
Everything I have found so far seems to reference PHP files as part of the process is this possible with an html file and if so how can I potentially accomplish it
This code:
RewriteEngine On
RewriteRule ^/?$ /boat-repair.html [NC,L]
Will serve up the file when you type in allservicemarine.com
I tried putting the target file in a series of sub directories hoping the directory names would show in the address bar,but that still just pulls up the target file. I have been searching for many hours to try to find a solution and would appreciate it if anyone could point me in the right direction to accomplish the task.
This is the working code I came up with:
RewriteEngine On
RewriteRule ^/?$ /boat-repair/electrical-system-repair [NC]
RewriteRule ^boat-repair/electrical-system-repair/?$ /index.html [NC]
The first rule tells the server to serve up: boat-repair/electrical-system-repair when the root directory is entered.
The second rule tells the server if the pattern: boat-repair/electrical-system-repair is matched to serve up index.html
The file served up (index.html) in the last step can be named anything you like as it will load, but not show in the address bar.
So after both rules are implemented you get: http://yoursitename.com/boat-repair/electrical-system-repair/ in the address bar, now I just need to figure out a way to remove the trailing slash.
These rules of course get put in the htaccess file.
In order for this to work you must have the folders named in the rules even if they are just dummy folders. If dummy folders be sure to put a text document in each folder named "DO NOT DELETE THIS FOLDER" so that six months down the road you do not look at these empty folders and delete them!
I have an application whose codebase is deployed inside a folder shop . The URL to the main application is http://myapp/shop/.
One of the links on my page reads
http://myapp/shop/website-design/design-urself.php
which I want to redirect to http://myapp/shop/website-design/index.php
The rule which I am using in my .htaccess file is :
RewriteEngine On
RewriteBase /
RewriteRule ^/website-design/design-urself.php /website-design/index.php [R=301]
But the link is wrongly being getting redirected to http://myapp/website-design/index.php
I tried by removing the leading slash (/) from the urls as :
RewriteRule ^website-design/design-urself.php website-design/index.php [R=301]
but still it doesn't work.
I can understand that probably changing the RewriteBase to shop will solve my problem.
However , the thing here is - going further, the folder name ("shop" in my case) can change . So , in that case I have to again go and modify the .htaccess , which is not desirable.
What is the appropriate RewriteRule I should use in this case?
UPDATE : I have my .htaccess file located at my document root , i.e, inside the folder shop and outside of all other folders residing inside shop.
I have searched a lot but cannot find the information i want. I have a domain http://mydomain.com, my html files are nested in 3 level subfolders (for example thingy.html is nested in t/h/i/ folder, testy.html nested in /t/e/s/ folder
Now i want to type http://mydomain.com/testy.html or http://mydomain.com/thingy.html in the browser, it should show the content of those files without being redirected to http://mydomain.com/t/h/i/thingy.html and http://mydomain.com/t/e/s/testy.html
Is this doable?
Could anyone please help me? I'm new to .htaccess
Unless there's some kind of deterministic whay these 3 level subfolders are named, you'll have to do each one explicitly and separately. For example, the the htaccess file in your document root, you can have:
RewriteEngine On
RewriteRule ^/?thingy.html$ /t/h/i/thingy.html [L]
RewriteRule ^/?testy.html$ /t/e/s/testy.html [L]
etc.
I am use Codeigniter to creat my site. it is a huge site with a lot of contents.
i use the default welcome controller for all pages.
the path is like this now
http://mydomain.com/index.php/welcome
and my folder structure is like this
/root
/codeigniter Application folder
/controller
/view
/static/
/images/
/css/
/pdf/
.htaccess
because i am doing the content first, so all the images are set to absolute patch (http://mydomain.com/static/images/foldername/pc.jpg)
now when i use the rewrite to remove "inde.php" and "welcome"
RewriteEngine on
RewriteCond $1 !^(index\.php|images|robots\.txt|system|pdf|sitemap\.xml|profile.htm|^([A-z,0-9,_,-]+).asp|(.*)\.pdf|phpadmin)
RewriteRule ^(.*)$ /index.php/welcome/$1 [L]
all css and image file are not accessible anymore. I have nearly a thousand pages with images. I don't have the time to change the page one by one. the deadline is coming, please help.
thanks
Have you tried adding the css-folder to your excluded rewriteconditions?
RewriteCond $1 !^(index\.php|images|robots\.txt|system|pdf|sitemap\.xml|profile.htm|^([A-z,0-9,_,-]+).asp|(.*)\.pdf|phpadmin)
Does not seem to exclude the folder css from rewriting (see images is excluded).
Try something like
RewriteCond $1 !^(index\.php|images|css|robots\.txt|system|pdf|sitemap\.xml|profile.htm|^([A-z,0-9,_,-]+).asp|(.*)\.pdf|phpadmin)
Good luck
I think the problem lies with your .htaccess file. We have a similar setup, and that url living outside of the application directory is available just as you have it with a direct url relative to its path. Check out the wiki at http://codeigniter.com/wiki/mod_rewrite for the correct way to set up your .htaccess file.
Edit to clarify: The url http://mydomain.com/static/images/foldername/pc.jpg should work. something about your .htaccess file is wrong.
RewriteCond $1 !^(static|index.php|images|robots.txt|system|pdf|sitemap.xml|profile.htm|^([A-z,0-9,_,-]+).asp|(.*).pdf|phpadmin)
I have a page deals.php which is placed at root directory that is being accessed by number of internal URLs with multi directory levels. for example this page would be accessed by both following urls.
http://domain/flights/asia/bangkok
http://domain/flights/bangkok
I am using this code in .htaccess to redirect to deals.php
Options +FollowSymlinks
RewriteEngine on
RewriteRule ^flights/asia/([^/]+)/?$ deals.php?country=$1 [NC]
RewriteRule ^flights/([^/]+)/?$ deals.php?country=$1 [NC]
Now the problem here coming is that on deals.php all the images, script and style sheet files are not opening properly. If I try to fix it against one URL by placing ../../ in addresses of all images, script and css, it dont work for other URL.
How to solve this problem? what are the options?
Easy: DO NOT use ../ in links to any resources (images/css/js/etc) -- always use URL that is relative to the WEBSITE ROOT -- that is a "requirement" when you dealing with nice/not-real/rewritten URLs as such URL rarely points to the physical file location.
Lets assume you have a logo that is located at http://www.example.com/images/logo.png.
Now, instead of ../images/logo.png and/or ../../images/logo.png ALWAYS use /images/logo.png.
i think what you want is placing an baseurl in html page, so all the relative path will related to the baseurl, not the current URL in the navigator bar