HTACCESS - can you set two rules? ending in / and not ?
Moderator: General Moderators
-
simonmlewis
- DevNet Master
- Posts: 4435
- Joined: Wed Oct 08, 2008 3:39 pm
- Location: United Kingdom
- Contact:
HTACCESS - can you set two rules? ending in / and not ?
[text]RewriteRule ^([^/\.]+)/?$ index.php?page=$1&menu=home [L][/text]
We have this rule in our HTACCESS. But if someone goes to: www.domain.com/help, it goes to the page and shows images.
If they go to www.domain.com/help/, it goes to the page but doesn't load the images.
a) why is this and
b) does it just need to rules to cover both endings?
We have this rule in our HTACCESS. But if someone goes to: www.domain.com/help, it goes to the page and shows images.
If they go to www.domain.com/help/, it goes to the page but doesn't load the images.
a) why is this and
b) does it just need to rules to cover both endings?
Love PHP. Love CSS. Love learning new tricks too.
All the best from the United Kingdom.
All the best from the United Kingdom.
Re: HTACCESS - can you set two rules? ending in / and not ?
a) Because you have your images and CSS pointing to URLs like
which are supposedly located in the current directory. If you're in /help then the image will be /image.jpg, but if you're in /help/ then the image is /help/image.jpg.
b) There's no problem with your rewriting. The problem is that you're not using absolute URLs for resources.
That will always reference /image.jpg regardless of what directory you're showing.
Code: Select all
<img src="image.jpg" />b) There's no problem with your rewriting. The problem is that you're not using absolute URLs for resources.
Code: Select all
<img src="/image.jpg" />-
simonmlewis
- DevNet Master
- Posts: 4435
- Joined: Wed Oct 08, 2008 3:39 pm
- Location: United Kingdom
- Contact:
Re: HTACCESS - can you set two rules? ending in / and not ?
I'm not. The images are all:
Yet the problem exists.
Code: Select all
<img src="/image.jpg" />Love PHP. Love CSS. Love learning new tricks too.
All the best from the United Kingdom.
All the best from the United Kingdom.
Re: HTACCESS - can you set two rules? ending in / and not ?
Then it's probably the other major problem: the RewriteRule applying to things it shouldn't.
I assumed you had a couple RewriteConds in there too. Do you? What's the whole thing?
I assumed you had a couple RewriteConds in there too. Do you? What's the whole thing?
-
simonmlewis
- DevNet Master
- Posts: 4435
- Joined: Wed Oct 08, 2008 3:39 pm
- Location: United Kingdom
- Contact:
Re: HTACCESS - can you set two rules? ending in / and not ?
Here is a snippet, fro mthe top, and a few rows.
Code: Select all
DirectoryIndex index.php index.html index.htm
order allow,deny
allow from all
Options +FollowSymLinks
Options +Indexes
RewriteEngine On
RewriteRule ^categ/([0-9]+)/([^/]+) /index.php?page=categ&c=$1&cname=$2&menu=sub [L]
RewriteRule ^([^/\.]+)/?$ index.php?page=$1&menu=home [L]
RewriteRule ^$ index.php?page=home&menu=home [L]Love PHP. Love CSS. Love learning new tricks too.
All the best from the United Kingdom.
All the best from the United Kingdom.
Re: HTACCESS - can you set two rules? ending in / and not ?
Sorry for the late reply. Vacation 
One of these broken images... Use something to look at the rendered HTML, like Chrome's Inspector or Firefox's dontrememberwhatitsbeenalongtime, to see not only where the images are going but what happens when the browser tries to request them.
Using Chrome as an example, you can right-click > Inspect Element on the image, then click on the src attribute that it shows in the HTML view. That should send you to the image it was trying to load. Does it go to the right URL? What happens when you go there?
One of these broken images... Use something to look at the rendered HTML, like Chrome's Inspector or Firefox's dontrememberwhatitsbeenalongtime, to see not only where the images are going but what happens when the browser tries to request them.
Using Chrome as an example, you can right-click > Inspect Element on the image, then click on the src attribute that it shows in the HTML view. That should send you to the image it was trying to load. Does it go to the right URL? What happens when you go there?
-
simonmlewis
- DevNet Master
- Posts: 4435
- Joined: Wed Oct 08, 2008 3:39 pm
- Location: United Kingdom
- Contact:
Re: HTACCESS - can you set two rules? ending in / and not ?
Sorry I am really not with you.
The image is pointing to /images/.....
This as far as I know is the root, then then images is the folder in the root. ie.
httpdocs/images.
So surely whether I am in fred.com/contact/, or fred.com/contact, it should still be looking in the root...??
The image is pointing to /images/.....
This as far as I know is the root, then then images is the folder in the root. ie.
httpdocs/images.
So surely whether I am in fred.com/contact/, or fred.com/contact, it should still be looking in the root...??
Love PHP. Love CSS. Love learning new tricks too.
All the best from the United Kingdom.
All the best from the United Kingdom.
Re: HTACCESS - can you set two rules? ending in / and not ?
Right... At some point the image stuff is breaking. Is it the URL? Probably not. But it wouldn't hurt to start at the beginning (the img src in the HTML) and follow it to the end (whatever the browser is actually downloading) to see where the problem is.
-
simonmlewis
- DevNet Master
- Posts: 4435
- Joined: Wed Oct 08, 2008 3:39 pm
- Location: United Kingdom
- Contact:
Re: HTACCESS - can you set two rules? ending in / and not ?
Ok, so even if it is:
<img src=/images/fred.jpg' />
It may not be looking in the right place....?
<img src=/images/fred.jpg' />
It may not be looking in the right place....?
Love PHP. Love CSS. Love learning new tricks too.
All the best from the United Kingdom.
All the best from the United Kingdom.
Re: HTACCESS - can you set two rules? ending in / and not ?
I'm sure the HTML has the right place.
You know how if you call up a stereotypical tech support place they tell you to make sure the power cords are plugged in and the whatevers are turned on? They're starting at the top of the list of things to check and working their way down. I'm doing the same thing.
You know how if you call up a stereotypical tech support place they tell you to make sure the power cords are plugged in and the whatevers are turned on? They're starting at the top of the list of things to check and working their way down. I'm doing the same thing.
-
simonmlewis
- DevNet Master
- Posts: 4435
- Joined: Wed Oct 08, 2008 3:39 pm
- Location: United Kingdom
- Contact:
Re: HTACCESS - can you set two rules? ending in / and not ?
Yeah I understand that. The answer is: the URL in question for the image is correct.
While I am on the HTACCESS subject, how do I get around this:
[text].....(36)File name too long: access to....[/text]
in the error log.
The filename is too long, but it's a filename that no longer exists. Somehow someone has cached it and we are getting a lot of errors.
The start of it is .../selector/.....
I've tried a PHP script to ask if that word is in the URL, but of course it errors before it reaches that. So how do I redirect a URL that starts with /selector, to the homepage, if it errors straight away - I can only assume I put something in the top of HTACCESS .... but what?
While I am on the HTACCESS subject, how do I get around this:
[text].....(36)File name too long: access to....[/text]
in the error log.
The filename is too long, but it's a filename that no longer exists. Somehow someone has cached it and we are getting a lot of errors.
The start of it is .../selector/.....
I've tried a PHP script to ask if that word is in the URL, but of course it errors before it reaches that. So how do I redirect a URL that starts with /selector, to the homepage, if it errors straight away - I can only assume I put something in the top of HTACCESS .... but what?
Love PHP. Love CSS. Love learning new tricks too.
All the best from the United Kingdom.
All the best from the United Kingdom.
Re: HTACCESS - can you set two rules? ending in / and not ?
Either the URL is wrong (which you've checked, it isn't) or there's some sort of URL rewriting which is interfering. None of the stuff you posted would match so it's not one of those.
1. What happens when you browse to the image directly?
2. Did you post all of your .htaccess?
Is it all /selector/* URLs that are gone?
1. What happens when you browse to the image directly?
2. Did you post all of your .htaccess?
Normally you should just let such things 404, but if it's causing actual errors then you should address it.simonmlewis wrote:While I am on the HTACCESS subject, how do I get around this:
[text].....(36)File name too long: access to....[/text]
in the error log.
The filename is too long, but it's a filename that no longer exists. Somehow someone has cached it and we are getting a lot of errors.
The start of it is .../selector/.....
I've tried a PHP script to ask if that word is in the URL, but of course it errors before it reaches that. So how do I redirect a URL that starts with /selector, to the homepage, if it errors straight away - I can only assume I put something in the top of HTACCESS .... but what?
Is it all /selector/* URLs that are gone?
-
simonmlewis
- DevNet Master
- Posts: 4435
- Joined: Wed Oct 08, 2008 3:39 pm
- Location: United Kingdom
- Contact:
Re: HTACCESS - can you set two rules? ending in / and not ?
We don't use selector.inc anymore, the file is deleted off the server. So it could be someone who knew it existing and is trying to scam it.
But yes, we want to abort ANY /selector/* urls.
Can it be done?
But yes, we want to abort ANY /selector/* urls.
Can it be done?
Love PHP. Love CSS. Love learning new tricks too.
All the best from the United Kingdom.
All the best from the United Kingdom.
Re: HTACCESS - can you set two rules? ending in / and not ?
Yes, I was just checking what it is you wanted to do.
You can use [R=404] to 404 things.
You can use [R=404] to 404 things.
Code: Select all
RewriteRule ^selector/ - [L,R=404]-
simonmlewis
- DevNet Master
- Posts: 4435
- Joined: Wed Oct 08, 2008 3:39 pm
- Location: United Kingdom
- Contact:
Re: HTACCESS - can you set two rules? ending in / and not ?
How would you go about pointing that to another url, such as /error ?
Love PHP. Love CSS. Love learning new tricks too.
All the best from the United Kingdom.
All the best from the United Kingdom.