What am I doing wrong?

Hi Everyone…

I am really new to friendly URLs.

please help me with this one… I have placed this in my .htaccess file. And I am on an Apache server.

RewriteEngine On

RewriteRule ^viewgallery/([0-9]+)/?$ viewgallery.php?cid=1 [NC,L]

To make the link

[noparse]http://www.123456.com/viewgallery.php?cid=1[/noparse]

look like this…

[noparse]http://www.123456.com/viewgallery/1/[/noparse]

What I am doing wrong… ? It is not working…

Any help is appreciated! Thank you very much…

your “rewrite” should be: viewgallery.php?cid=$1
You left out the DOLLAR SIGN.

Two more things:

  1. You have changed directory levels so relative links will not work correctly.

  2. You visitors’ browsers don’t know which level to believe they’re at with the optional trailing slash.

Have a look at the tutorial Article linked in my signature for the first - eliminate the trailing slashes for the second.

Regards,

DK

check this:

RewriteEngine On
RewriteRule ^viewgallery/([0-9]+)/?$ viewgallery.php?cid=1 [L]

hamo,

As noted above, that’s wrong on two levels, the $1 variable and the two directory levels for viewgallery.php to deal with for supporting files (css, js, gif, jpg, etc).

Regards,

DK

Thank you dklynn and hamo17…

dklynn…

I am a complete newbie… so I rewrote

RewriteEngine On

RewriteRule ^viewgallery/([0-9]+)?$ viewgallery.php?cid=$1 [NC,L]
RewriteRule ^viewgallery/([0-9]+)?/$ viewgallery.php?cid=$1 [NC,L]

Is this correct… ?

Like you said… CSS file is missing…

To get around this seeming “bad feature” of mod_rewrite, you can use absolute links throughout your site instead of relative links OR use HTML’s <base> tag to identify the real location:

<head>
<!-- … other head tags withOUT relative links …–>
<base href=“http://www.example.com/display.php” />
<!-- … other head tags with relative links … –>
</head>

Note that an absolute link (with either a leading / to denote DocumentRoot OR the full URL) is required as you are trying to “fix” the problem with relative links.

I don’t understand this dklynn… so how do I display the page with CSS properties, my background… etc, etc…?

May be I should have asked this question before… Apache’s mod_rewrite does it change the links you see on the browser when a ‘next’ button is pressed for a picture on a website … does mod_rewrite change the link physically…?

or

does Apache’s mod_rewrite, changes what viewers see on the browser to “http://www.123456.com/viewgallery/1/” from “http://www.123456.com/viewgallery.php?cid=1” …

Or the point of mod_rewrite is something different?

Thanks,

Rajeev

Raj,

We all start as a newbie … you’ll be an expert soon!

Correct? Vs what? Okay, I’m NOT a fan of trailing slashes (except for directories) so my vote is NO. Looking back, I didn’t refer you to the tutorial linked in my signature - go look for the section titled “Relative Links Are Missing!” and look at the options that you have when you won’t let the visitors’ browsers know what directory level they’re in (the trailing / changes that level).

Apache’s mod_rewrite DOES change the directory level. Your code shows that you use links to viewgallery/{id number} (first subdirectory level) AND viewgallery/{id number}/ (second subdirectory level) - obviously, viewgallery.php is in the DocumentRoot (zero subdirectory level). BECAUSE your redirection is not a 301 (which shows the redirection to the visitor’s browser), the visitor’s browser will be requesting links relative to either the first or second level subdirectory (unless <base> is used).

Regards,

DK