Web Hosting Forum | Lunarpages


*
Welcome, Guest. Please login or register.
Did you miss your activation email?



Login with username, password and session length
February 09, 2012, 10:41:19 AM

Pages: [1]   Go Down
  Print  
Author Topic: some mod_rewrite help  (Read 1726 times)
cristobal151
Space Explorer
***
Offline Offline

Posts: 8


« on: August 18, 2009, 04:14:13 PM »

Hi:
i have some trouble with mod rewrite in my site...
first off all, the site is a addon domain, and the the path is /home/USER/public_html/bborganico/

i want to do this:
www.bborganico.cl/categoria/1/name.html -> www.bborganico.cl/categoria.php?categoria=1&titulo=name
so i have:
RewriteRule ^categoria/([0-9]+)/(.*).html$ /categoria.php?$categoria=$1&titulo=$2 [L]
but when i prove this with www.bborganico.cl/categoria/1/packs-ofertas.html, the navigator redirects to www.bborganico.cl/categoria/1/index.php and give a 404 err, because i don't have a directory 1, and 1/packs-ofertas.html file

i need to do this too:
www.bborganico.cl/contenido/name.html -> www.bboeganico.cl/name.php

if you can help y I'll be very grateful
thanks...

PD: i don't speak English, i speck Spanish
Logged
Mitch
Berserker Poster
*****
Offline Offline

Posts: 12838


WWW
« Reply #1 on: August 19, 2009, 03:56:29 AM »

Checking out your web site (very nice one by the way) it looks like you already have your links formatted in this way:

http://www.bborganico.cl/producto.php?producto=40

What script or what type of content management do you have running your web site and shopping cart?
Logged

New to Web Site Hosting? Check Out the Lunarpages Blog Hosting Guide!


Follow us @lunarpages on Twitter!
Important Threads: Read This Before Posting! | Lunarforums Rules! | Mitch's Link of the Day!
Also, be sure to check out and subscribe to the Lunartics Blog and the Lunarpages Newsletter !

Need Web Hosting Help? Check out the Lunarpages Web Hosting Wiki. It has tons of tips, tutorials and resources!
cristobal151
Space Explorer
***
Offline Offline

Posts: 8


« Reply #2 on: August 19, 2009, 07:02:30 AM »

Checking out your web site (very nice one by the way) it looks like you already have your links formatted in this way:

http://www.bborganico.cl/producto.php?producto=40

What script or what type of content management do you have running your web site and shopping cart?

it my systeme, i created...

i have the links formated that way, but i need to use this way www.bborganico.cl/categoria/1/name.html but don't work with the rewriterulethat i put...
the idea is to use friendly url for people and google...
Logged
MrPhil
Berserker Poster
*****
Offline Offline

Posts: 5083



« Reply #3 on: August 19, 2009, 07:48:03 AM »

first off all, the site is a addon domain, and the the path is /home/USER/public_html/bborganico/

Is this your public_html/.htaccess, or your public_html/bborganico/.htaccess file? If the first one, I think you will have to include /bborganico in the rewrite (both pattern (left) and replacement (right). If it's the second one, I think you can start with /categoria...

Code:
RewriteRule ^categoria/([0-9]+)/(.*).html$ /categoria.php?$categoria=$1&titulo=$2 [L]

looks mostly OK. Is that $categoria a typo? The "$" should not be there. If there is no RewriteCond before this, you can omit the [L]. Do you have RewriteEngine On in the file? If this is in public_html/bborganico/.htaccess, try
Code:
RewriteRule ^categoria/([0-9]+)/(.*)\.html$  /categoria.php?categoria=$1&titulo=$2

If this is in public_html/.htaccess, try
Code:
RewriteRule ^bborganico/categoria/([0-9]+)/(.*)\.html$  /bborganico/categoria.php?categoria=$1&titulo=$2

Quote

Try
Code:
RewriteRule  ^(.*)\.html$  /$1.php
Make sure you do it after the other rule (categoria), so that you don't fail to match that rewrite. That will change .html to .php. If you also want to get rid of the "contenido/",
Code:
RewriteRule  ^contenido/(.*)\.html$  /$1.php
should do it.

Quote
PD: i don't speak English, i speck Spanish

There is a board on this forum specifically for questions and answers in Spanish: Spanish Hosting Questions (Preguntas en Espa~nol). You might be more comfortable asking there, although your English is quite understandable.
Logged

cristobal151
Space Explorer
***
Offline Offline

Posts: 8


« Reply #4 on: August 19, 2009, 08:33:27 AM »

hi:
first of all, thans...

i have de .htacces in public_html/bborganico/.htaccess

i have this now
Code:
RewriteRule ^categoria/([0-9]+)/(.*)\.html$  /categoria.php?categoria=$1&titulo=$2

but it giveme a 404 error
Code:
Not Found

The requested URL /1/packs-ofertas.html was not found on this server.

Additionally, a 404 Not Found error was encountered while trying to use an ErrorDocument to handle the request.

and the
Code:
RewriteRule  ^contenido/(.*)\.html$  /$1.php
give the same error

this is my complete .htaccess
Code:
AddHandler application/x-httpd-php5 .php5 .php4 .php .php3 .php2 .phtml
AddType application/x-httpd-php5 .php5 .php4 .php .php3 .php2 .phtml

RewriteEngine On
RewriteRule ^categoria/([0-9]+)/(.*)\.html$  /categoria.php?categoria=$1&titulo=$2
RewriteRule ^contenido/(.*)\.html$  /$1.php



Logged
cristobal151
Space Explorer
***
Offline Offline

Posts: 8


« Reply #5 on: August 19, 2009, 10:02:58 AM »

now it work, but i have to put Options +FollowSymLinks son my .htaccess is now
Code:
AddHandler application/x-httpd-php5 .php5 .php4 .php .php3 .php2 .phtml
AddType application/x-httpd-php5 .php5 .php4 .php .php3 .php2 .phtml

Options +FollowSymLinks
RewriteEngine On
RewriteRule ^categoria/([0-9]+)/(.*)\.html$ /categoria.php?categoria=$1&titulo=$2
RewriteRule ^contenido/(.*)\.html$ /$1.php

but i have another problem now, dont recognizes the path to the images, css or javascript, can i use a rewriterole for thas directoris to??, how would be that??
thanks
Logged
MrPhil
Berserker Poster
*****
Offline Offline

Posts: 5083



« Reply #6 on: August 19, 2009, 10:16:14 AM »

OK, some servers seem to require the FollowSymLinks setting.

I see you do have your CSS file /home/USER/public_html/bborganico/css/tienda.css (http://www.bborganico.cl/css/tienda.css). My guess is that the browser is sending the request for the file to http://www.bborganico.cl/categoria/1/css/tienda.css. Same thing for .js and image files. Since you're redirecting only .html files to the actual directory, that could be the problem. The easiest fix might be to give CSS, JS, and image files an absolute path (href="/css/tienda.css"), rather than trying to redirect all these special cases. Try it on the CSS file and get back to us if it doesn't help.
Logged

cristobal151
Space Explorer
***
Offline Offline

Posts: 8


« Reply #7 on: August 19, 2009, 12:44:38 PM »

to do that i have to make many changes, because the structure of the site...

i add this to the .htacces i work very well
Code:
RewriteRule ^categoria/([0-9]+)/css/(.*)$ /css/$2
RewriteRule ^categoria/([0-9]+)/js/(.*)$ /js/$2
RewriteRule ^categoria/([0-9]+)/imagenes/(.*)$ /imagenes/$2
RewriteRule ^categoria/([0-9]+)/catalogo/(.*)$ /catalogo/$2

now i haver other problem and y hopoe you can helpme:
i have a page of messages for the whle site name: mensajes.php?opcion=1&opcion=2 and in the category page if the category don't exist the page redirect to the message page, but now how i have another address the redirection don't work

like this
www.bborganico.cl/categoria.php?categoria=666 -> www.bborganico.cl/mensajes.php?opcion=1&opcion=2
www.bborganico.cl/categoria/666/some-here.html -> www.bborganico.cl/categoria/666/mensajes.php?opcion=1&opcion=2

cant i have another rewriterule to make a redireccion from www.bborganico.cl/categoria/666/mensajes.php?opcion=1&opcion=2 to www.bborganico.cl/mensajes.php?opcion=1&opcion=2
thanks
Logged
MrPhil
Berserker Poster
*****
Offline Offline

Posts: 5083



« Reply #8 on: August 19, 2009, 01:11:34 PM »

URL rewriting for the CSS, JS, and image files is fine. Just be sure that you're catching all the possible places this is needed (when you rewrite .html to .php).

I'm not quite sure what you're trying to do here with the other rewrites. Are these the URLs that would be coming in from the outside, or are they special cases after you've done your other rewrites? You are free to add more URL rewrites to handle special cases. Just be careful to either handle them before you rewrite the more general cases, or do your rewriting after, knowing exactly what the URLs would have been rewritten to by the "general" code.

If you continue to have trouble with this, please post your entire .htaccess file or files here, along with some examples of what doesn't work (and what is supposed to happen), and I can try to explain what changes are needed.
Logged

cristobal151
Space Explorer
***
Offline Offline

Posts: 8


« Reply #9 on: August 19, 2009, 09:07:59 PM »

hi:
i fix the problem using aboslute path...
so, my final .htacces is this:
Code:
AddHandler application/x-httpd-php5 .php5 .php4 .php .php3 .php2 .phtml
AddType application/x-httpd-php5 .php5 .php4 .php .php3 .php2 .phtml

Options +FollowSymLinks
RewriteEngine On
RewriteRule ^categoria/([0-9]+)/(.*)\.html$ /categoria.php?categoria=$1&titulo=$2
RewriteRule ^categoria/([0-9]+)/(.*)\.html&_pagi_pg=([0-9]+)$ /categoria.php?categoria=$1&titulo=$2&&_pagi_pg=$3
RewriteRule ^producto/([0-9]+)/(.*)\.html$ /producto.php?producto=$1&titulo=$2
RewriteRule ^contenido/(.*)\.html$ /$1.php

#css y js
RewriteRule ^categoria/([0-9]+)/css/(.*)$ /css/$2
RewriteRule ^producto/([0-9]+)/css/(.*)$ /css/$2
RewriteRule ^contenido/([0-9]+)/css/(.*)$ /css/$2
RewriteRule ^categoria/([0-9]+)/js/(.*)$ /js/$2
RewriteRule ^producto/([0-9]+)/js/(.*)$ /js/$2
RewriteRule ^contenido/([0-9]+)/js/(.*)$ /js/$2

#imagenes
RewriteRule ^categoria/([0-9]+)/imagenes/(.*)$ /imagenes/$2
RewriteRule ^producto/([0-9]+)/imagenes/(.*)$ /imagenes/$2
RewriteRule ^contenido/([0-9]+)/imagenes/(.*)$ /imagenes/$2
RewriteRule ^categoria/([0-9]+)/catalogo/(.*)$ /catalogo/$2
RewriteRule ^producto/([0-9]+)/catalogo/(.*)$ /catalogo/$2
RewriteRule ^contenido/([0-9]+)/catalogo/(.*)$ /catalogo/$2
now all works...

thank you very much MrPhil ...
Logged
Pages: [1]   Go Up
  Print  
 
Jump to: