Dear alli'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 problemi 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 thenthe news page it display like thishttp://localhost/menu.php?ph_sc_menu_id=1the 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 displayhttp://localhost/news/so how i gonna do? do i used mod_rewrite i try to do like this

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

hengwebdeveloper
—
2012-12-20T09:49:18Z —
#3

David K. LynnThank so much i will read your Tutorial Article

hengwebdeveloper
—
2012-12-20T10:13:25Z —
#4

David K.LynnThanks 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 FoundThe requested URL /test.php[L] was not found on this server.======================================================

thanks for you help

dklynn
—
2012-12-21T08:48:41Z —
#5

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

hengwebdeveloper
—
2012-12-21T12:38:57Z —
#6

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

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.

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.

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

hengwebdeveloper
—
2013-01-01T05:04:00Z —
#11

DKi 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 i still have problem the same way i don't understand.Regard,Heng

dklynn
—
2013-01-01T07:54:07Z —
#12

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

hengwebdeveloper
—
2013-01-03T16:22:47Z —
#13

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

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!