DeanWhitehouse Posted October 15, 2008 Share Posted October 15, 2008 ok, i am looking to add some mod rewrite to my sites which have long url's I have seen a few things but don't get them, can some explain how i can rewrite a url. I want to start simple e.g. mysite.com/page.php to be mysite.com/Page Thanks, Blade Quote Link to comment Share on other sites More sharing options...
Lamez Posted October 15, 2008 Share Posted October 15, 2008 1.Post in the right board 2.Find the mod_rewrite cheat sheet, which is located in the right board. HUGE HINT: http://www.phpfreaks.com/forums/index.php/board,50.0.html Quote Link to comment Share on other sites More sharing options...
DeanWhitehouse Posted October 15, 2008 Author Share Posted October 15, 2008 Do you know what , i never even knew there was a mod rewrite board. Quote Link to comment Share on other sites More sharing options...
wildteen88 Posted October 15, 2008 Share Posted October 15, 2008 An article on mod_rewrite Quote Link to comment Share on other sites More sharing options...
DeanWhitehouse Posted October 15, 2008 Author Share Posted October 15, 2008 RewriteEngine On RewriteBase / RewriteRule ^Home/?$ index.php [NC,L] Causes a 500 Internal Server Error, when i put this code in my .htaccess Quote Link to comment Share on other sites More sharing options...
DeanWhitehouse Posted October 15, 2008 Author Share Posted October 15, 2008 Ok, no longer causes an error found out rewrite mod was disabled, but still doesnt work, when i enter site.com/Home comes up with a 404 error Quote Link to comment Share on other sites More sharing options...
Lamez Posted October 15, 2008 Share Posted October 15, 2008 as a novice as well, here is what I used Options +FollowSymLinks Options +Indexes RewriteEngine On RewriteRule ^([A-Za-z0-9-]+)/?$ user/profile.php?user=$1 [L] what is say is this: it allows the string to contain numbers and letters, it uses the file under the user directory called profile.php then it takes the ?user=username, so it all comes out to site.com/username Quote Link to comment Share on other sites More sharing options...
wildteen88 Posted October 15, 2008 Share Posted October 15, 2008 Your rewrite rule will one work if your url is site.com/Home/ If you dont want to have the ending slash then use RewriteEngine On RewriteBase / RewriteRule /Home /index.php [NC,L] Quote Link to comment Share on other sites More sharing options...
DeanWhitehouse Posted October 16, 2008 Author Share Posted October 16, 2008 I tried that wildteen, putting a / after home site.com/Home/ And then also tried using your code, both produce 404 errors again. How do i know if my server is set up correct (i am using WAMP) @lamez, i am just doing basic rewriting ,e.g. page.php = /page/ So i don't that code yet. Quote Link to comment Share on other sites More sharing options...
wildteen88 Posted October 16, 2008 Share Posted October 16, 2008 Can you post the full 404 error message here. My earlier code should of been RewriteEngine On RewriteBase / RewriteRule Home /index.php [NC,L] Quote Link to comment Share on other sites More sharing options...
DeanWhitehouse Posted October 16, 2008 Author Share Posted October 16, 2008 Haha, works now thnks, but one small problem it takes me back to my WAMP server page, not the folders index page. Do i need to do RewriteRule Home /Folder Name/index.php [NC,L] Quote Link to comment Share on other sites More sharing options...
wildteen88 Posted October 16, 2008 Share Posted October 16, 2008 Yes you'll need to define the path to the file the rewrite rule applies to. EDIT: Or you could just move the .htaccess file in to your '/Folder Name' folder Quote Link to comment Share on other sites More sharing options...
DeanWhitehouse Posted October 16, 2008 Author Share Posted October 16, 2008 Thats the thing it is in the correct folder , it just always redirects to the WAMP page I tried defining a folder but didn't work RewriteRule Home /folder name/index.php [NC,L] Quote Link to comment Share on other sites More sharing options...
DeanWhitehouse Posted October 16, 2008 Author Share Posted October 16, 2008 Solved it, it was due to the space in my folder name. Quote Link to comment Share on other sites More sharing options...
DeanWhitehouse Posted October 16, 2008 Author Share Posted October 16, 2008 This is wierd RewriteRule Home /Property-Agent/index.php [NC,L] RewriteRule News /Property-Agent/news.php [NC,L] RewriteRule Search /Property-Agent/search.php [NC,L] Search and News causes 500 Internal Server Error Internal Server Error The server encountered an internal error or misconfiguration and was unable to complete your request. Please contact the server administrator, admin@localhost and inform them of the time the error occurred, and anything you might have done that may have caused the error. More information about this error may be available in the server error log. Quote Link to comment Share on other sites More sharing options...
wildteen88 Posted October 16, 2008 Share Posted October 16, 2008 Umm, instresting. Use RewriteEngine On RewriteBase / RewriteRule ^Home /Property-Agent/index.php [NC,L] RewriteRule ^News /Property-Agent/news.php [NC,L] RewriteRule ^Search /Property-Agent/search.php [NC,L] Quote Link to comment Share on other sites More sharing options...
DeanWhitehouse Posted October 16, 2008 Author Share Posted October 16, 2008 Still no luck I can't understand why it doesnt work. When i remove the folder name e.g. RewriteRule ^News /news.php [NC,L] It comes up with a 404 error, Not Found The requested URL /news.php was not found on this server. Quote Link to comment Share on other sites More sharing options...
wildteen88 Posted October 16, 2008 Share Posted October 16, 2008 Where is your .htaccess file located? Post the full path here. Quote Link to comment Share on other sites More sharing options...
DeanWhitehouse Posted October 16, 2008 Author Share Posted October 16, 2008 C:\wamp\www\Property-Agent\.htacccess And all the site files are located there. From the log [Thu Oct 16 19:54:45 2008] [error] [client 127.0.0.1] script 'C:/wamp/www/news.php' not found or unable to stat Thats the wrong path but the path i specified is RewriteRule ^News /Property-Agent/news.php [NC,L] Quote Link to comment Share on other sites More sharing options...
wildteen88 Posted October 16, 2008 Share Posted October 16, 2008 Are ok now I see whats up. Use RewriteEngine On RewriteBase /Property-Agent RewriteRule ^Home index.php [NC,L] RewriteRule ^News news.php [NC,L] RewriteRule ^Search search.php [NC,L] Quote Link to comment Share on other sites More sharing options...
DeanWhitehouse Posted October 16, 2008 Author Share Posted October 16, 2008 Genius Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.