Enjoy an ad free experience by logging in. Not a member yet?
Register .
05-17-2009, 02:48 AM
PM User |
#1
New to the CF scene
Join Date: May 2009
Posts: 6
Thanks: 1
Thanked 0 Times in 0 Posts
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.
05-17-2009, 07:00 AM
PM User |
#2
Master Coder
Join Date: Dec 2007
Posts: 6,682
Thanks: 436
Thanked 890 Times in 879 Posts
05-17-2009, 01:56 PM
PM User |
#3
New to the CF scene
Join Date: May 2009
Posts: 6
Thanks: 1
Thanked 0 Times in 0 Posts
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
.
05-17-2009, 02:00 PM
PM User |
#4
Master Coder
Join Date: Dec 2007
Posts: 6,682
Thanks: 436
Thanked 890 Times in 879 Posts
Quote:
Originally Posted by
samcroft
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
05-17-2009, 02:24 PM
PM User |
#5
New to the CF scene
Join Date: May 2009
Posts: 6
Thanks: 1
Thanked 0 Times in 0 Posts
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
.
05-17-2009, 02:43 PM
PM User |
#6
Master Coder
Join Date: Dec 2007
Posts: 6,682
Thanks: 436
Thanked 890 Times in 879 Posts
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
05-17-2009, 02:50 PM
PM User |
#7
New to the CF scene
Join Date: May 2009
Posts: 6
Thanks: 1
Thanked 0 Times in 0 Posts
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
05-17-2009, 02:55 PM
PM User |
#8
Master Coder
Join Date: Dec 2007
Posts: 6,682
Thanks: 436
Thanked 890 Times in 879 Posts
Quote:
Originally Posted by
samcroft
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
05-17-2009, 02:56 PM
PM User |
#9
Supreme Master coder!
Join Date: Mar 2007
Location: N/A
Posts: 14,680
Thanks: 158
Thanked 2,182 Times in 2,169 Posts
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)
05-17-2009, 03:04 PM
PM User |
#10
Master Coder
Join Date: Dec 2007
Posts: 6,682
Thanks: 436
Thanked 890 Times in 879 Posts
Quote:
Originally Posted by
abduraooft
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
06-11-2009, 08:36 PM
PM User |
#11
New to the CF scene
Join Date: May 2009
Posts: 6
Thanks: 1
Thanked 0 Times in 0 Posts
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.
06-11-2009, 09:49 PM
PM User |
#12
Regular Coder
Join Date: Oct 2004
Posts: 330
Thanks: 0
Thanked 13 Times in 13 Posts
Relative paths can also be fixed with the HTML <base> element.
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]
Users who have thanked schleppel for this post:
06-14-2009, 04:52 PM
PM User |
#13
New to the CF scene
Join Date: May 2009
Posts: 6
Thanks: 1
Thanked 0 Times in 0 Posts
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
06-16-2009, 11:50 PM
PM User |
#14
Regular Coder
Join Date: Oct 2004
Posts: 330
Thanks: 0
Thanked 13 Times in 13 Posts
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);
Jump To Top of Thread
Thread Tools
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
HTML code is Off
All times are GMT +1. The time now is 08:55 PM .
Advertisement
Log in to turn off these ads.