help pls

New to mod_rewrite? This is a good place to start.

help pls

Postby antonhilman » Sun May 03, 2009 5:34 am

-------------------------1-----------------------------

REAL URL: *.com/?mod=berita&c=5&id=1234

SEO URL: *.com/berita/politik/c/5/1234

politik: cat name
c: cat mark
5: id cat
1234: id news

there are 2 url:
1. *.com/?mod=berita&c=5&id=1234
2. *.com/?mod=berita&d=5&id=1234

-------------------------2-----------------------------

REAL URL:
*.com/?mod=artikel&id=1234
*.com/?mod=artikel

SEO URL:
*.com/artikel/1234
*.com/artikel


============i try this:=========

Options +FollowSymLinks
RewriteEngine On
RewriteBase /antara

RewriteCond %{ENV:REDIRECT_STATUS} ^$

RewriteCond %{SCRIPT_FILENAME} !-d

RewriteRule ^(.*)/(.*)/(.*)/([0-9]+)/([0-9]+)$ index.php?mod=$1&$3=$4&id=$5
================

but
$_GET[mod] = "index.php/payakumbuh/d"
???? why not $_GET[mod] ="berita" ?
antonhilman
 
Posts: 13
Joined: Sat May 02, 2009 6:48 pm

Postby richardk » Sun May 03, 2009 9:38 am

Do you have any other rules?

Try
Code: Select all
Options +FollowSymLinks

RewriteEngine On

RewriteRule ^([^/]+)/[^/]+/([^/]+)/([0-9]+)/([0-9]+)/?$ /antara/index.php?mod=$1&$2=$3&id=$4 [QSA,L]
richardk
 
Posts: 8800
Joined: Wed Dec 21, 2005 7:50 am

Postby antonhilman » Sun May 03, 2009 6:43 pm

i have 3 global rule sir:

1 *.com/mod-name
REAL: ?mod=mod-name
ex: *.com/berita OR *.com/artikel

2 *.com/mod-name/cat-name
REAL: ?mod=mod-name&j=cat-name
ex: *.com/berita/padang OR *.com/artikel/politik

3 *.com/mod-name/cat-name/id-number/news-title.html
REAL: ?mod=mod-name&j=cat-name&id=id-number
ex: *.com/berita/padang/1234/padang-oke.html

but i have problem with file name. i have file berita.php anf artikel.php
my SEO url have the same name like: *.com/berita and *.com/artikel

for 3 rule above the mod_rewrite like what?
if i write rule one by one its good?
ex:
RewriteRule ^(.*)$ index.php?mod=$1
RewriteRule ^berita/(.*)/([0-9]+)/(.*).html$
RewriteRule ^artikel/(.*)/([0-9]+)/(.*).html$

thx for help
antonhilman
 
Posts: 13
Joined: Sat May 02, 2009 6:48 pm

Postby richardk » Mon May 04, 2009 12:37 pm

Try
Code: Select all
Options +FollowSymLinks -MultiViews

RewriteEngine On

RewriteCond %{SCIRPT_FILENAME} -f [OR]
RewriteCond %{SCIRPT_FILENAME} -d
RewriteRule .* - [L]

# /mod-name --> /index.php?mod=mod-name
RewriteRule ^([^/]+)/?$ /index.php?mod=$1 [QSA,L]

# /mod-name/cat-name --> /index.php?mod=mod-name&j=cat-name
RewriteRule ^([^/]+)/([^/]+)/?$ /index.php?mod=$1&j=$2 [QSA,L]

# /mod-name/cat-name/id-number/news-title.html --> /index.php?mod=mod-name&j=cat-name&id=id-number
RewriteRule ^([^/]+)/([^/]+)/([0-9]+)/[^/]+\.html$ /index.php?mod=$1&j=$2&id=$3 [QSA,L]


but i have problem with file name. i have file berita.php anf artikel.php
my SEO url have the same name like: *.com/berita and *.com/artikel

I don't understand.
richardk
 
Posts: 8800
Joined: Wed Dec 21, 2005 7:50 am

Postby antonhilman » Mon May 04, 2009 11:26 pm

i mean, i have the same php filename with SEO url.

my php file: index.php, berita.php, artikel.php

and

my seo url:

*.com/berita --> view list of berita category

*.com/artikel --> view list of artikel category

it's oke with mod_rewrite rule?
rewriteCond %{SCIRPT_FILENAME} -f <-- mean is not same with filename,right?

========================

RewriteRule ^([^/]+)/?$ index.php?mod=$1 [QSA,L]
RewriteRule ^([^/]+)/([^/]+)/?$ index.php?mod=$1&j=$2 [QSA,L]
RewriteRule ^([^/]+)/([^/]+)/([0-9]+)/[^/]+\.html$ index.php?mod=$1&j=$2&id=$3 [QSA,L]



BTW thx, you rule works. there r problem when i access www.*.com directly, may we need rule for direct access. ex: www.web-name.com

my web do not load css. but when i access *.com/berita OR *.com/berita/politik OR *.com/berita/politik/123/news-title.html it works good

thx
antonhilman
 
Posts: 13
Joined: Sat May 02, 2009 6:48 pm

Postby richardk » Tue May 05, 2009 11:10 am

it's oke with mod_rewrite rule?
rewriteCond %{SCIRPT_FILENAME} -f <-- mean is not same with filename,right?

It should. Are you having problems with it?

there r problem when i access www.*.com directly, may we need rule for direct access. ex: www.web-name.com

What is the problems?
What happens?
What should happen?

my web do not load css. but when i access *.com/berita OR *.com/berita/politik OR *.com/berita/politik/123/news-title.html it works good

Are you using relative paths?

FAQ: Relative paths to images, JavaScript, CSS and other external/linked files are broken.
richardk
 
Posts: 8800
Joined: Wed Dec 21, 2005 7:50 am

Postby antonhilman » Wed May 06, 2009 7:07 am

i use absolute path, when i try $_GET[mod] in index.php it contain "index.php" value

$_GET[mod] = index.php

===========

Options +FollowSymLinks -MultiViews

RewriteEngine On
RewriteBase /antara

RewriteCond %{SCIRPT_FILENAME} -f [OR]
RewriteCond %{SCIRPT_FILENAME} -d
RewriteRule .* - [L]

RewriteRule ^([^/]+)/?$ index.php?mod=$1 [QSA,L]

RewriteRule ^([^/]+)/([^/]+)/?$ index.php?mod=$1&j=$2 [QSA,L] <=== IT WORKS WHEN I REMOVE THIS RULE sir ???? but i need seo url: *.com/mod-name/cat-name/ hiksz :(( help

RewriteRule ^([^/]+)/([^/]+)/([0-9]+)/[^/]+\.html$ index.php?mod=$1&j=$2&id=$3 [QSA,L]
antonhilman
 
Posts: 13
Joined: Sat May 02, 2009 6:48 pm

Postby richardk » Wed May 06, 2009 9:44 am

Replace all
Code: Select all
%{SCIRPT_FILENAME}

with
Code: Select all
%{SCRIPT_FILENAME}
richardk
 
Posts: 8800
Joined: Wed Dec 21, 2005 7:50 am

Postby antonhilman » Wed May 06, 2009 5:15 pm

i dont understand, its very similar the same code

%{SCIRPT_FILENAME}
%{SCRIPT_FILENAME}

???
antonhilman
 
Posts: 13
Joined: Sat May 02, 2009 6:48 pm

Postby richardk » Thu May 07, 2009 1:55 pm

SCIRPT is typo. SCRIPT is correct.
richardk
 
Posts: 8800
Joined: Wed Dec 21, 2005 7:50 am

Next

Return to Beginner's Corner

Who is online

Users browsing this forum: No registered users and 6 guests

cron