mod_rewrite Help

Discussions about Apache mod Rewrite, .htaccess, Use, experiences ... URL Rewriting.

Moderator: Moderators

mod_rewrite Help

Postby stevan » Mon Sep 10, 2007 11:15 pm

I have never done this before and I have a script I am trying to make works I fixed almost all the other errors BUT I wnat to make it so the pages are like my old script

Right now the main page web adress is

-http://www.webadress.net/links/-page-0.html I want to change it to

-http://www.webadress.net/links

and when on a Cat page it looks like this

-http://www.webadress.net/links/Education-page-0.html I want it to be

-http://www.webadress.net/links/Education

The second page would be

-http://www.webadress.net/links/Education/index2.html


Here is the file for it
Code: Select all
RewriteEngine on

#categories
RewriteRule  ^(.*)-page-(.*).html$  index.php?command=select&category=$1&pager_cmd=$2
#details page
RewriteRule  ^details-(.*).html$  index.php?command=details&id=$1

RewriteRule ^add-site-(.*).html       index.php?command=add_site&category=$1



THXS for any Help

Steve
stevan
 
Posts: 3
Joined: Mon Sep 10, 2007 11:06 pm

Advertisement

Postby dcz » Thu Sep 13, 2007 8:15 am

Given that the .htaccess will not change your URLs but will only allow them to work, the cat rewriterule you are searching for should be close to this :


Code: Select all
#categories
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-l
RewriteRule  ^links/([a-z0-9_-])+/?(index([0-9]+)\.html)?$  /links/index.php?command=select&category=$1&pager_cmd=$3 [QSA,L,NC]


-http://www.webadress.net/links seems to be a real folder, so there is no need to add a rewriterule for it, it should load the default page.

The rewriterule mentions the links/ folder and should as is be implemented in the domains root .htaccess.

The three RewriteCond are here to make sure that we do not mess up with a physical file, since we are trying to match something like links/cattitle. We do not have a clear ending criteria (like .html or /), so the rewriterule will handle anything without dots in the links/ folder.

++
Useful links :
SEO Forum || SEO Directory || SEO phpBB || Search
____________________

Liens Utiles :
Forum référencement || Annuaire référencement || Référencement phpBB || Recherche
dcz
Admin
Admin
 
Posts: 21219
Joined: Fri Apr 28, 2006 9:03 pm

Postby stevan » Thu Sep 13, 2007 12:09 pm

I change the code to what you said and what happens now is the address is the same BUT when i click on a Cat I get a 404
stevan
 
Posts: 3
Joined: Mon Sep 10, 2007 11:06 pm

Postby dcz » Fri Sep 14, 2007 7:56 am

dcz wrote:Given that the .htaccess will not change your URLs but will only allow them to work


The .htaccess only makes it possible to use rewritten URLs, it does not alter the links outputted. This is to be done in your script.

++
Useful links :
SEO Forum || SEO Directory || SEO phpBB || Search
____________________

Liens Utiles :
Forum référencement || Annuaire référencement || Référencement phpBB || Recherche
dcz
Admin
Admin
 
Posts: 21219
Joined: Fri Apr 28, 2006 9:03 pm


Return to Apache mod Rewrite

 


  • Related topics
    Replies
    Views
    Last post

Who is online

Users browsing this forum: No registered users and 3 guests