Help me

Dear all
i’m a new for .htaccess i try to read the book it took me 5days ago and still not understand what is .htaccess or i read not right the book or whatever i just want to hide my url here my problem
i used php for my own website designed database with mysql i designed my menu in database so the index.php it don’t have any problem then
the news page it display like this
http://localhost/menu.php?ph_sc_menu_id=1
the menu.php it query my database field name ph_sc_menu_id=1 i don’t want it to display like this i want it display
http://localhost/news/
so how i gonna do? do i used mod_rewrite i try to do like this

Options +FollowSymlinks
RewriteEngine On
RewriteRule ^news(/)$ http://localhost/menu.php?ph_sc_menu_id=9 [R=301,NC,L]

but it not working pls help thank advance

heng,

What you’re asking can only be done with a RewriteMap - some way to tell Apache which URI should receive which value of ph_sc_menu_id. IMHO, it would be better for you to have a read of the tutorial linked in my signature (including test server setup, regex through sample code for typical problems).

What you should have done before starting your website is contemplate a navigation scheme. I would have picked one with the pages being extensionless file names which can then be handled by mod_rewrite (sent to the correct script for handling - your use of a database merely to select a page is a bit out of the ordinary (unless a CMS, of course).

Regards,

DK

David K. Lynn
Thank so much i will read your Tutorial Article

David K.Lynn
Thanks so much for take time to read my question now i have problem, i read your tutorial at test now i found the problem with my local server when i create 3 file as you command my local server it not working properly i used WAMP SERVER on window 7 32bit here the message honestly i’m family with Apache or Unix
Not Found
The requested URL /test.php[L] was not found on this server.

thanks for you help

heng,

Sorry, I didn’t understand whether your problem was resolved or not.

From what you’ve posted about receiving a 404, it’s likely that you’ve not placed test.php in WAMP’s htdocs or www (or equivalent) folder. It should be co-located with the .htaccess file you’re using with your mod_rewrite code.

Regards,

DK

Dear David K. Lynn,
i found the problem now it working :slight_smile: and still read your tutorial.

Thanks so much :slight_smile:

Dear DK
why my mod_rewrite it not working? here my .htaccess file

Options +FollowSymlinks
Options -Indexes
RewriteEngine On
RewriteRule ^test\\.html$ test.php [L] #this 1 working perfectly
RewriteRule ^menu.php/([0-9]+)/$ menu.php?ph_sc_menu_id=$1 [NC,L] #this not working

it still display http://localhost/menu.php?ph_sc_menu_id=9 in my url the same before so what the problem?
Regard,
Heng

heng,

The only things wrong are the use of menu.php as a directory and the No Case flag in the RewriteRule (URIs are case sensitive). I would have dropped the .php after menu in the regex to show that you don’t want Apache to serve menu.php just yet (but that requires you to account for the change in directory level for your relative links).

If you’ve requested the “normal URI” as you’ve displayed above, it’s because it’s your job as webmaster NOT to create that link but to use menu/9/ (I also loathe trailing slashes like this) which would work (with corrected regex as suggested above).

Please RE-read the tutorial as this should have been obvious.

Tip: To see whether the problem is within your mod_rewrite or menu.php script, use [R=301,L] for your flags … just remove the R=301, before uploading to a production server.

Regards,

DK

DK,
i have no idea now because my .htaccess file
Options +FollowSymlinks
Options +Indexes
RewriteEngine on
RewriteRule ^test\.html$ test.php [L] #woking
RewriteRule ^news\.html$ /menu.php?ph_sc_menu_id=9 [L] #are not working
RewriteRule ^tips\.html$ /menu.php?ph_sc_menu_id=10 [L]
RewriteRule ^reviews\.html$ /menu.php?ph_sc_menu_id=11 [L]

it still display url http://localhost/menu.php?ph_sc_menu_id=9
how i gonna do?

Regard,
Heng

heng,

Did you try

That will show the redirection. Removing the R=301 will hide an INTERNAL redirection. It is YOUR job to create links in your new format then use mod_rewrite to redirect back to a file (and query string) that Apache can serve. Again, RE-read the tutorial linked in my signature.

Once you’ve gotten that far, then know that the four simple redirections you have would be better (faster) made with a mod_alias Redirect statement.

Regards,

DK

DK
i have no idea now i need to host but i’m afraid of because i used to have someone stuck my web that why i worried now those web was closed :slight_smile: i still have problem the same way i don’t understand.
Regard,
Heng

Heng,

I’m sorry but your last post made no sense to me. I thought we’d resolved your issues earlier. Please have another read of the mod_rewrite tutorial then, if you need good hosting, I’d recommend you look seriously at WebHostingBuzz.com or WebHostingBuzz.co.uk (the UK version if you prefer to host in England vs US) as they are an excellent hosting company.

Regards,

DK

Dear DK,
Happy New Year!!
sorry for i made no sense to you because those website it dead, now my new website it gonna publish soon but i still have problem with .htaccess that’s why i keep asking you sorry about that, today i watch the tutorial at youtube now my htaccess it work, but it still have 1 small problem below it’s the problem hope you give me some light

Options +FollowSymlinks
RewriteEngine on
RewriteCond %{REQUEST_URI} news/
RewriteRule news/ http://localhost/menu.php?ph_sc_menu_id=9

if i key in my url box
http://localhost/news/ it working
but if i click on the menu it still display
http://localhost/menu.php?ph_sc_menu_id=9
so any solution for this? because the menu it calling from my database below it what i calling from my database using php

while($row = $statement->fetch(PDO::FETCH_ASSOC)){
		echo '<li><a href="menu.php?ph_sc_menu_id='.$row['ph_sc_menu_id'].'">'.$row['ph_sc_menu_name'].'</a></li>';
	}

thank DK
Regards,
Heng

Hi Heng!

Thanks! I hope you’re having a great New Year, too!

The problem you have is that the redirection is absolute - as far as Apache knows, you’ve redirected to a DIFFERENT domain. Because there is no need to repeat the domain with an internal redirection, just leave off the http://localhost/. Then, there is no reason to duplicate the regex which is (and should be) in the RewriteRule with your RewriteCond so just eliminate the RewriteCond statement (it’s redundant - which makes its use wasteful of your Apache resources).

In other words, all you need is …

RewriteEngine on
RewriteRule news/$ menu.php?ph_sc_menu_id=9 [L]

… which can be transferred to your production website without changing the domain name!

Regards,

DK