URL Rewriting with htaccess - .htaccess

if iam giving my url as http://localhost/york/aboutus.php it is working fine, but the problem i am having is that if i provide http://localhost/york/aboutus.php/ or any character after the trailing slash of the above url and then if load that page then all the css and javascript files are not working. Please provide me the solution to this problem.. Thanks in advance..

The problem is most likely the way you are including the javascript / css files in your page. With more details you will probably get a more detailed answer, but I would guess you are using .htaccess to rewrite the page in question and then in your html you are using a relative path for the src/link attributes of js/css. Every forward slash in your URL, the clients browser will assume is a directory and it will calculate relative paths accordingly.
The solution is to provide all your src/js paths relative to Root not your cwd. That is to say they should begin with a forward slash and then have the full path from your root directory. This way the clients browser will request http://www.domain.com/path/to/style.css, regardless of how many slashes are in the pages URL.

Related

Use .htaccess to allow subfolders both with and without trailing slash

I am about to move my html files from the root folder to a couple of subfolders.
The default setting my host is using is to show the trailing slash for the subfolders and no slash for the html files. If the browser requests a subfolder without trailing slash, a 301 redirect to the same folder with trailing slash is returned. The files are shown without html extension thanks to a .htaccess snippet.
I think I like the approach to distinguish the subfolders from the files. In my case the contents of the index files will be different than the ordinary files.
However, I am not as convinced as many others that duplicate content is a disaster. I cannot be sure how my websites will develop in the future and what I will think about trailing slashes and such, so an easy forward compatible strategy is therefore desirable. For that reason I am considering to abandon the 301 redirect and instead allow the browser to send urls to subfolders both with and without the trailing slash and with response 200 OK in both cases. Yes, that leads to duplicate content, but I will will keep the trailing slash on all subfolders on all internal and canonical links, so in practice, I do not think it is a disaster. And Google and Bing and others should be able to figure things out.
I have my sites on a shared server configured via directadmin and (probably) no access to other configuration files and do not know how the default setting has been accomplished. I guess I need to do something in .htaccess to change the default setting but I am not sure what.
Is there anybody who knows how to override the default setting so that I get rid of the 301 redirect in the mentioned case and instead send 200?
I found this interesting document https://httpd.apache.org/docs/2.4/mod/mod_dir.html#directoryindex , but I can not interpret it, and I do not dare to do any trial and error. Hope that somebody can give me a hint.

Dealing with Laravel routing without htaccess mod_rewrite capability

So, currently, I do not have the ability to utilize .htaccess, I have no control over the server config at the moment, so I have to live with /index.php/ in my URL. That's not a problem, but there is one issue.
If I go to webserver.com/site/index.php everything works fine. But, if I go to webserver.com/site/ (without index.php) the site loads but all the links are broken (relative to /site/ instead of /site/index.php/).
I've tried various ways to build the links with url() and route() but I can't get anything to work short of hard-coding the full url for every link.
Any ideas?

hide image path possible with htaccess?

I got image path like that http://blablablabla.com/Admin/img/blablabla.jpg but i do not want to show this path user can i hide this URL with htaccess ?
For example : user will see path like that http://blablablabla.com/Info/img/blablabla.jpg but i have not Info folder this is possible ? so i do not want to see users never see my images paths is way is useful or not i'm not sure tell your ideas which way to most secure to hide my path
Rewriting your url will not make a difference security-wise. If the only security you have is hoping that no-one will ever know that a certain folder exists, then you have no security at all.
The requested rewrite can be done by placing the following directives in a .htaccess file in the www-root of your website.
RewriteEngine on
RewriteRule ^Info/img/([^/]+)$ Admin/img/$1 [L]
This is an internal rewrite that rewrites the url that is requested to an internal url that points to an actual file. $1 is replaced by the first capture group. See the documentation for more information.

How can I redirect and then rewrite url in same file for pretty URL?

I have just been asked to migrate a site from one server to another for a site that I did not build. They have a lot of links to pages that dont exist.
<a href="app/batteries">
This is not actually a directory in the site, but there is an app.php file in the root directory. I have gotten it to display the products by redirecting anything to the app/ directory to app.php?app=. The value of ?app= is dynamic, so any solution would need to be dynamic. I have simply used the redirect statement in the htaccess file to get it to the app.php page. Is there a way to get the url back to the pretty url after a redirect?
Any help would be awesome. Thanks in advance.
You should use ModRewrite instead, for matching a pretty url with regexps, and converting into the url using the app.php.
The rewrite is local to the server, so the visitor sees only pretty urls.

Magento Relative Paths of images on localhost

I have a website based on magento and it works well. Couple days ago I downloaded the website to make a local copy, everything went fine, everything works.
but... on my landing pages, I use relative paths for my images and landing pages dont show the relative paths, I thought it was htaccess problem, so I enabled mod rewrite in xampp, AllowOverrides is on - All, downloaded htaccess file from ftp and copied in my local, development website root.
still the same problem. Example:
<br /> <img title="Headphones" src="/media/pages/home/headphones.jpg" alt="Headphones" width="442" height="200" />
(I edited html tags, it doesnt let me post them here, but they are correct on my websites)
This code works well on my live website, but on my localhost it doesnt load an image. When I check it in firebug, it says "failed to load given URL". URL is correct though, same url works well on my live website.
Any ideas please? help is much appreciated : ))
Edit: If I change relative paths of images in firebug and add two dots before the slash like this >> ../relative path here << then the images show up well, I dont get it, why does it show images on my live website relative paths without two dots in the beginning and why doesnt it show images on my localhost?
You have wrong idea about what path (note that url and path are different things) is relative and what is absolute:
this is absolute path from your domain root and those all are equivalent:
src="/media/pages/home/headphones.jpg"
src="http://localhost/media/pages/home/headphones.jpg"
src="http://productiondomain.com/media/pages/home/headphones.jpg"
this is a relative path from the page/dir you are visiting and are available from this point only (if defined correctly):
src="media/pages/home/headphones.jpg"
If your site is on localhost then your image is looked up from abs.url+abs.path and you should verify that the /media directory is on your domain root. If your site is on some subfolder on your localhost then the path just won't match and you should either rename all paths or add base dir rule to htaccess or base href rule to your html.

Resources