Go Back   CodingForums.com > :: Server side development > Apache configuration

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rating: Thread Rating: 9 votes, 3.56 average.
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 05-17-2009, 02:48 AM   PM User | #1
samcroft
New to the CF scene

 
Join Date: May 2009
Posts: 6
Thanks: 1
Thanked 0 Times in 0 Posts
samcroft is an unknown quantity at this point
Trying to rewrite some URLs, confused.

Code:
Options +FollowSymLinks 
RewriteEngine On 
RewriteRule ^(.*?)/(.*?)/(.*?)/(.*?)/(.*)$ index.php?page=$1-$2-$3-$4-$5 
RewriteRule ^(.*?)/(.*?)/(.*?)/(.*)$ index.php?page=$1-$2-$3-$4 
RewriteRule ^(.*?)/(.*?)/(.*)$ index.php?page=$1-$2-$3 
RewriteRule ^(.*?)/(.*)$ index.php?page=$1-$2 
RewriteRule ^(.*)$ index.php?page=$1
I'm trying to get some URLs to convert like follows

http://www.domain.com/index.php?page=word1-word2-word3 to convert to http://www.domain.com/word1/word2/word3/

With those current rules it just goes to what index.php outputs, rather than index.php?page=word1-word2-word3 . The same goes if I go up to word5, or down to word2.

Although,

http://www.domain.com/index.php?page=word1 WORKS, it will convert to http://www.domain.com/word1/ - it just won't do anything further on.

Does anyone know what I need to do to make this work?

Thanks for any help you can provide, my knowledge of this is very limited.
samcroft is offline   Reply With Quote
Old 05-17-2009, 07:00 AM   PM User | #2
oesxyl
Master Coder


 
Join Date: Dec 2007
Posts: 6,682
Thanks: 436
Thanked 890 Times in 879 Posts
oesxyl is a jewel in the roughoesxyl is a jewel in the roughoesxyl is a jewel in the rough
from this:

http://httpd.apache.org/docs/2.0/mod/mod_rewrite.html

see the "Ruleset Processing":

http://httpd.apache.org/docs/2.0/mod...nternalRuleset

and read about "flags":

http://httpd.apache.org/docs/2.0/mod...l#rewriteflags

try to solve your problem by adding the L flag to each rule.

best regards
oesxyl is offline   Reply With Quote
Old 05-17-2009, 01:56 PM   PM User | #3
samcroft
New to the CF scene

 
Join Date: May 2009
Posts: 6
Thanks: 1
Thanked 0 Times in 0 Posts
samcroft is an unknown quantity at this point
I've tried addin [L] to each rule as follows:
Code:
Options +FollowSymLinks
RewriteEngine On 
RewriteRule ^(.*?)/(.*?)/(.*?)/(.*?)/(.*)$ index.php?page=$1-$2-$3-$4-$5 [L]
RewriteRule ^(.*?)/(.*?)/(.*?)/(.*)$ index.php?page=$1-$2-$3-$4 [L]
RewriteRule ^(.*?)/(.*?)/(.*)$ index.php?page=$1-$2-$3 [L]
RewriteRule ^(.*?)/(.*)$ index.php?page=$1-$2 [L]
RewriteRule ^(.*)$ index.php?page=$1 [L]
With no success .
samcroft is offline   Reply With Quote
Old 05-17-2009, 02:00 PM   PM User | #4
oesxyl
Master Coder


 
Join Date: Dec 2007
Posts: 6,682
Thanks: 436
Thanked 890 Times in 879 Posts
oesxyl is a jewel in the roughoesxyl is a jewel in the roughoesxyl is a jewel in the rough
Quote:
Originally Posted by samcroft View Post
I've tried addin [L] to each rule as follows:
Code:
Options +FollowSymLinks
RewriteEngine On 
RewriteRule ^(.*?)/(.*?)/(.*?)/(.*?)/(.*)$ index.php?page=$1-$2-$3-$4-$5 [L]
RewriteRule ^(.*?)/(.*?)/(.*?)/(.*)$ index.php?page=$1-$2-$3-$4 [L]
RewriteRule ^(.*?)/(.*?)/(.*)$ index.php?page=$1-$2-$3 [L]
RewriteRule ^(.*?)/(.*)$ index.php?page=$1-$2 [L]
RewriteRule ^(.*)$ index.php?page=$1 [L]
With no success .
try this way:

Code:
Options +FollowSymLinks
RewriteEngine On 
RewriteRule ^(.*?)\/(.*)$ index.php?page=$1-$2 [L]
RewriteRule ^(.*)$ index.php?page=$1 [L]
best regards
oesxyl is offline   Reply With Quote
Old 05-17-2009, 02:24 PM   PM User | #5
samcroft
New to the CF scene

 
Join Date: May 2009
Posts: 6
Thanks: 1
Thanked 0 Times in 0 Posts
samcroft is an unknown quantity at this point
I've managed to get this working, seems like it was a problem within the index.php file rather than .htaccess in the end.

----

In my scripts for all the image locations it is doing it as the new directory, /images

so its trying to say the images are in /word1/word2/word3/images

rather than /images

This is probably since the file locations are like this:

Code:
<img src="images/top_shared.gif">
Is there any way to make sure it does treat it in the right directory, rather than me having to replace them all with http://www.domain.com/images/image.gif ?

---

Also, it no longer lets me browse directories which were there previously, which have contents in which I need to view, it just returns the index page .
samcroft is offline   Reply With Quote
Old 05-17-2009, 02:43 PM   PM User | #6
oesxyl
Master Coder


 
Join Date: Dec 2007
Posts: 6,682
Thanks: 436
Thanked 890 Times in 879 Posts
oesxyl is a jewel in the roughoesxyl is a jewel in the roughoesxyl is a jewel in the rough
try to put on top before other rules:
Code:
RewriteRule ^images\/(.+)$ images/$1 [L]
after first match redirection will stop because of L.

best regards
oesxyl is offline   Reply With Quote
Old 05-17-2009, 02:50 PM   PM User | #7
samcroft
New to the CF scene

 
Join Date: May 2009
Posts: 6
Thanks: 1
Thanked 0 Times in 0 Posts
samcroft is an unknown quantity at this point
I've tried that with no success:

Code:
Options +FollowSymLinks
RewriteEngine On
RewriteRule ^images\/(.+)$ images/$1 [L]
RewriteRule ^(.*?)\/(.*?)\/(.*?)\/(.*?)\/(.*)$ index.php?page=$1z$2z$3z$4z$5 [L]
RewriteRule ^(.*?)\/(.*?)\/(.*?)\/(.*)$ index.php?page=$1z$2z$3z$4 [L]
RewriteRule ^(.*?)\/(.*?)\/(.*)$ index.php?page=$1z$2z$3 [L]
RewriteRule ^(.*?)\/(.*)$ index.php?page=$1z$2 [L]
RewriteRule ^(.*)$ index.php?page=$1 [L]
It is still coming up with the same wrong file path
samcroft is offline   Reply With Quote
Old 05-17-2009, 02:55 PM   PM User | #8
oesxyl
Master Coder


 
Join Date: Dec 2007
Posts: 6,682
Thanks: 436
Thanked 890 Times in 879 Posts
oesxyl is a jewel in the roughoesxyl is a jewel in the roughoesxyl is a jewel in the rough
Quote:
Originally Posted by samcroft View Post
I've tried that with no success:

Code:
Options +FollowSymLinks
RewriteEngine On
RewriteRule ^images\/(.+)$ images/$1 [L]
RewriteRule ^(.*?)\/(.*?)\/(.*?)\/(.*?)\/(.*)$ index.php?page=$1z$2z$3z$4z$5 [L]
RewriteRule ^(.*?)\/(.*?)\/(.*?)\/(.*)$ index.php?page=$1z$2z$3z$4 [L]
RewriteRule ^(.*?)\/(.*?)\/(.*)$ index.php?page=$1z$2z$3 [L]
RewriteRule ^(.*?)\/(.*)$ index.php?page=$1z$2 [L]
RewriteRule ^(.*)$ index.php?page=$1 [L]
It is still coming up with the same wrong file path
can you post a link? also, take it step by step, comment all lines in htaccess and starting from top do change on the line untill work, then go to next line.

something like this:
Code:
Options +FollowSymLinks
RewriteEngine On
RewriteRule ^images/(.+)$ images/$1 [L]
#RewriteRule ^(.*?)\/(.*?)\/(.*?)\/(.*?)\/(.*)$ index.php?page=$1z$2z$3z$4z$5 [L]
#RewriteRule ^(.*?)\/(.*?)\/(.*?)\/(.*)$ index.php?page=$1z$2z$3z$4 [L]
#RewriteRule ^(.*?)\/(.*?)\/(.*)$ index.php?page=$1z$2z$3 [L]
#RewriteRule ^(.*?)\/(.*)$ index.php?page=$1z$2 [L]
RewriteRule ^(.*)$ index.php?page=$1 [L]
remove slash, maybe this is the problem.

best regards
oesxyl is offline   Reply With Quote
Old 05-17-2009, 02:56 PM   PM User | #9
abduraooft
Supreme Master coder!

 
abduraooft's Avatar
 
Join Date: Mar 2007
Location: N/A
Posts: 14,678
Thanks: 158
Thanked 2,182 Times in 2,169 Posts
abduraooft is just really niceabduraooft is just really niceabduraooft is just really niceabduraooft is just really niceabduraooft is just really nice
Quote:
This is probably since the file locations are like this:

Code:
<img src="images/top_shared.gif">
Is there any way to make sure it does treat it in the right directory, rather than me having to replace them all with http://www.domain.com/images/image.gif ?
Yes, make them like
Code:
<img src="/images/top_shared.gif">
(The same absolute path technique can be used with files like css and javascript, to avoid messing their paths with the results of mod_rewrite )
__________________
Quote:
The Dream is not what you see in sleep; Dream is the thing which doesn't let you sleep. --(Dr. APJ. Abdul Kalam)
abduraooft is offline   Reply With Quote
Old 05-17-2009, 03:04 PM   PM User | #10
oesxyl
Master Coder


 
Join Date: Dec 2007
Posts: 6,682
Thanks: 436
Thanked 890 Times in 879 Posts
oesxyl is a jewel in the roughoesxyl is a jewel in the roughoesxyl is a jewel in the rough
Quote:
Originally Posted by abduraooft View Post
Yes, make them like
Code:
<img src="/images/top_shared.gif">
(The same absolute path technique can be used with files like css and javascript, to avoid messing their paths with the results of mod_rewrite )
that means "to replace them all",

best regards
oesxyl is offline   Reply With Quote
Old 06-11-2009, 08:36 PM   PM User | #11
samcroft
New to the CF scene

 
Join Date: May 2009
Posts: 6
Thanks: 1
Thanked 0 Times in 0 Posts
samcroft is an unknown quantity at this point
Hi everyone,

Thanks for all of your help so far. I had to leave this problem for a while due to having to do some other things.

The image fix worked great, another similar problem has cropped up though.

I've got some folders which I want to get to on the site.

One of the folders I want to get to is http://www.domain.com/blog/ which has a wordpress blog inside of it.

When I try and load that URL, it just pulls up the site index page.

I added the same sort of code which I did for images but it isn't working.

My .htaccess at current:
Code:
Options +FollowSymLinks
RewriteEngine On
RewriteRule ^images\/(.+)$ images/$1 [L]
RewriteRule ^blog\/(.+)$ blog/$1 [L]
RewriteRule ^(.*?)\/(.*?)\/(.*?)\/(.*?)\/(.*)$ index.php?page=$1z$2z$3z$4z$5 [L]
RewriteRule ^(.*?)\/(.*?)\/(.*?)\/(.*)$ index.php?page=$1z$2z$3z$4 [L]
RewriteRule ^(.*?)\/(.*?)\/(.*)$ index.php?page=$1z$2z$3 [L]
RewriteRule ^(.*?)\/(.*)$ index.php?page=$1z$2 [L]
RewriteRule ^(.*)$ index.php?page=$1 [L]
Any help you can provide would be great, Thanks.
samcroft is offline   Reply With Quote
Old 06-11-2009, 09:49 PM   PM User | #12
schleppel
Regular Coder

 
Join Date: Oct 2004
Posts: 330
Thanks: 0
Thanked 13 Times in 13 Posts
schleppel is an unknown quantity at this point
Relative paths can also be fixed with the HTML <base> element.

Code:
^blog\/(.+)$
does not match /blog/. Try
Code:
Options +FollowSymLinks

RewriteEngine On

# Ignore /blog and /images.
RewriteRule ^(blog|images)(/.*)?$ - [L]

RewriteRule ^([^/]+)/([^/]+)/([^/]+)/([^/]+)/([^/]+)/?$ /index.php?page=$1z$2z$3z$4z$5 [L]
RewriteRule ^([^/]+)/([^/]+)/([^/]+)/([^/]+)/?$         /index.php?page=$1z$2z$3z$4    [L]
RewriteRule ^([^/]+)/([^/]+)/([^/]+)/?$                 /index.php?page=$1z$2z$3       [L]
RewriteRule ^([^/]+)/([^/]+)/?$                         /index.php?page=$1z$2          [L]
RewriteRule ^([^/]+)/?$                                 /index.php?page=$1             [L]
schleppel is offline   Reply With Quote
Users who have thanked schleppel for this post:
samcroft (06-14-2009)
Old 06-14-2009, 04:52 PM   PM User | #13
samcroft
New to the CF scene

 
Join Date: May 2009
Posts: 6
Thanks: 1
Thanked 0 Times in 0 Posts
samcroft is an unknown quantity at this point
Thanks, that worked great.

Something which I've noticed about the new way it processes URLs is that even if there isn't a index.php?page=XXXXXXXXXXX, that it will still give the homepage.

Is there any way it can be that if there is NOT a relevant index.php?page that it shows an not found error? I'm just thinking that this will make search engines like Google not too happy with content which is the same.

Thanks,
Sam
samcroft is offline   Reply With Quote
Old 06-16-2009, 11:50 PM   PM User | #14
schleppel
Regular Coder

 
Join Date: Oct 2004
Posts: 330
Thanks: 0
Thanked 13 Times in 13 Posts
schleppel is an unknown quantity at this point
Do you mean when someone accesses example.com/fake/page they see the homepage and not a 404 error? To fix that you will have to edit your PHP script as mod_rewrite does not know if a page exists or not. If/when you do, send a 404 header with the PHP header() function
Code:
header('Content-Type: text/html', true, 404);
schleppel is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 04:05 AM.


Advertisement
Log in to turn off these ads.