maccy93 Posted December 10, 2011 Share Posted December 10, 2011 mod rewrite on easy php: EasyPHP says to set the following in apache config : http://www.easyphp.org/faq.php#0 Uncomment LoadModule rewrite_module modules/mod_rewrite.so In <Directory "${path}/www"> section replace AllowOverride None by AllowOverride All I have done as the guide requested on easyPHP and restarted the easyPHP. writing a modrewite into the .htaccess following this guide: http://www.debian-administration.org/articles/136 Resulted in a .htaccess like so: RewriteEngine on RewriteRule ^/route/([A-Za-z0-9]+)$ /?route=$1 [PT] With this all in place and the url of the easyPHP index page is: http: //127.0.0.1:8080/testsite/ I added a link on the home page like this: http: //127.0.0.1:8080/testsite/route/hello but the link doesnt work. the .htaccess isn't kicking in it seems. Is it not meant to be seen in the php as: http: //127.0.0.1:8080/testsite/?route=hello So that i can grab the route from the $_GET? Quote Link to comment https://forums.phpfreaks.com/topic/252900-get-variables-with-mod-rewrite/ Share on other sites More sharing options...
jcbones Posted December 11, 2011 Share Posted December 11, 2011 but the link doesnt work. the .htaccess isn't kicking in it seems. Is it not meant to be seen in the php as: http: //127.0.0.1:8080/testsite/?route=hello Yes, and that is how your server is seeing it, but that isn't a valid filepath. You must point your mod-rewrite to a valid file path. Maybe something like: RewriteEngine on RewriteRule ^/route/([A-Za-z0-9]+)$ index.php?route=$1 [PT] This is assuming that your .htaccess file resides in the testsite directory, and you want it to open the index file. Quote Link to comment https://forums.phpfreaks.com/topic/252900-get-variables-with-mod-rewrite/#findComment-1296678 Share on other sites More sharing options...
maccy93 Posted December 11, 2011 Author Share Posted December 11, 2011 jcbones, thanks... but it didn't work. I have now scrapped easy php and am just testing it on my site live instead. Mod_rewite is definitely enabled on my live server as I have 404 and 403 errors usually being redirected fine. I disbaled them for the time being to see if the mod rewrite was workingL: Ok, so i'm lost... I've been following a few different guides on mod rewrite but i cant get it to work... the guy who wrote this guide http://anantgarg.com/2009/03/13/write-your-own-php-mvc-framework-part-1/ uses an ifModule which i treid out but then commented out. This is my .htaccess: Options -Indexes #ErrorDocument 404 http://www.mysite.com #ErrorDocument 403 http://www.mysite.com #<IfModule mod_rewrite.c> RewriteEngine on RewriteRule ^/route/([A-Za-z0-9]+)$ index.php?route=$1 [PT] #</IfModule> In the index.php, i have the following to see what is getting through. Which works fine if I just go to www.mysite.com?var=value: if(!empty($_GET)) { print_r($_GET); } But if i enter www.mysite.com/route/hello I expect my index.php to print out Array ( [route] => 'hello' ) In the source. But instead I keep getting a 404 error. Have i missed something? Is there any other tests to see if mod_rewrite is working properly of not? Quote Link to comment https://forums.phpfreaks.com/topic/252900-get-variables-with-mod-rewrite/#findComment-1296819 Share on other sites More sharing options...
maccy93 Posted December 11, 2011 Author Share Posted December 11, 2011 If the mod_rewrite was running perfectly on my server, shoudl the following .htaccess file in my web root change the url from www.mysite.com/route/hello to www.mysite.com?route=hello RewriteEngine on RewriteRule ^/route/([A-Za-z0-9]+)$ index.php?route=$1 [PT] (im trying to deduce which bit i have got wrong, a server setting or my .htaccess, although the .htaccess for 403 and 404 redirects was working fine before) Quote Link to comment https://forums.phpfreaks.com/topic/252900-get-variables-with-mod-rewrite/#findComment-1296829 Share on other sites More sharing options...
jcbones Posted December 14, 2011 Share Posted December 14, 2011 Lets work through this route from a basic standpoint. 1. Place this file in your ROOT directory. .htaccess Options +FollowSymlinks RewriteEngine on RewriteRule ^(.*).htm$ testmodwrite.php 2. Place this file in your root directory: testmodwrite.php <?php echo '<h1>Mod re-write has just sent you to this PHP file from a htm request!</h1>'; ?> 3. If this works, then you can slowly add rules until it works as desired. Mod re-write can be confusing to some trying to learn it. 4. For further help you can set the RewriteLogLevel to 3 or higher (de-bugging only), and make sure you can view the RewriteLog file. Manual to Mod rewrite Quote Link to comment https://forums.phpfreaks.com/topic/252900-get-variables-with-mod-rewrite/#findComment-1297682 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.