web.com/var/var TO web.com/index.php?page=$var&subpage=$

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

web.com/var/var TO web.com/index.php?page=$var&subpage=$

Postby GreasySpoon » Sat Sep 05, 2009 2:50 pm

Hey all im having some trouble with this bit of code...

Code: Select all
Options +FollowSymLinks

RewriteEngine On
RewriteBase /

RewriteCond %{SCRIPT_FILENAME} !-f
RewriteCond %{SCRIPT_FILENAME} !-d
RewriteRule ^([^/]+)/?([^/]+)/?$ /index.php?page=$1&subpage=$2 [QSA,L]


Im try to turn this URL > www.domain.com/page/subpage (the 'page' and 'subpage' are varibles)

Into this on the severside > www.domain.com/index.php?page=$page&subpage=$subpage

Ive been editing the above code for a while now and im getting nowhere :(. Thanks in advance if anyone can help me out. :)
GreasySpoon
 
Posts: 8
Joined: Wed Jul 09, 2008 2:50 pm

Postby richardk » Sun Sep 06, 2009 3:36 pm

What happens when you go to /page/subpage?
Does this mod_rewrite test work?

Code: Select all
Options +FollowSymLinks

RewriteEngine On

RewriteCond %{SCRIPT_FILENAME} !-f
RewriteCond %{SCRIPT_FILENAME} !-d
RewriteRule ^([^/]+)(?:/([^/]+))/?$ /index.php?page=$1&subpage=$2 [QSA,L]
richardk
 
Posts: 8800
Joined: Wed Dec 21, 2005 7:50 am

Postby GreasySpoon » Sun Sep 06, 2009 3:58 pm

Thanks for the reply :) Mod_rewrite is defintly on :), unfortunately it doesnt completely solve my problem :(

Links like this "domain.com/page" come up as a 404 'not found'.

Where as links in this format "domain.com/page/subpage" load but arent render correctly.
Last edited by GreasySpoon on Sun Sep 06, 2009 4:34 pm, edited 1 time in total.
GreasySpoon
 
Posts: 8
Joined: Wed Jul 09, 2008 2:50 pm

Postby GreasySpoon » Sun Sep 06, 2009 4:33 pm

Found a solution :) If anyone is interested here it is...

Code: Select all
Options +FollowSymLinks

RewriteEngine on

RewriteRule ^([^/\.]+)/?$ /index.php?page=$1 [L]

RewriteRule ^([^/\.]+)/([^/\.]+)/?$ /index.php?page=$1&subpage=$2 [L]
GreasySpoon
 
Posts: 8
Joined: Wed Jul 09, 2008 2:50 pm

Postby richardk » Mon Sep 07, 2009 10:38 am

Where as links in this format "domain.com/page/subpage" load but arent render correctly.

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


Return to Beginner's Corner

Who is online

Users browsing this forum: No registered users and 23 guests

cron