phpnewby1918 Posted January 23, 2011 Share Posted January 23, 2011 Hi, I've been looking into the apache mod_rewrite for quite a few days now, but i can't seem to get it to work. I have read around a lot tyring to understand it more. I believe my server does allow the rewrite as i did: RewriteRule ^somepage.html somepage.php And that worked fine. I am trying to rewrite URL so its prettier for this page. I wanted to start of with a basic (if there is a basic one) I have a page called 'about.php' where i pass a get variable to recall a more in depth article from the introductory text on about.php. for example about.php?x=jonathon goes into more depth about 'jonathon' I would as one could imagine like to rewrite this URL so that it looks like: about/jonathon/ So i have tried this .htaccess rule: <IfModule mod_rewrite.c> Options +FollowSymLinks RewriteEngine On RewriteRule ^about/([A-Za-z\+]+)/ about.php?x=$1 [NC] </IfModule> But nothing changes in my url. I have had quite a lot of attempts at this, unfortuantely to no avail and read many articles and guides Could someone show me the error of my ways please Any help very appreciated Jonathon Quote Link to comment https://forums.phpfreaks.com/topic/225403-rewrite-base-help/ Share on other sites More sharing options...
strago Posted January 28, 2011 Share Posted January 28, 2011 Options +FollowSymLinks +Indexes RewriteEngine on RewriteBase / RewriteRule ^about/([^.]+)/$ about.php?x=$1 [L] Quote Link to comment https://forums.phpfreaks.com/topic/225403-rewrite-base-help/#findComment-1166306 Share on other sites More sharing options...
phpnewby1918 Posted January 28, 2011 Author Share Posted January 28, 2011 Hi thanks for your reply. I went to this option, what do you think of it? I did try yours, but it didnt seem to work - sadly. mine was this: Options +FollowSymLinks RewriteEngine on RewriteCond %{SCRIPT_FILENAME} !-d RewriteCond %{SCRIPT_FILENAME} !-f RewriteRule ^about/?$ about.php RewriteRule ^about/([A-Za-z\+\-]+)/?$ ./about.php?x=$1 You clearly know more about Apache than me, so be interested on your take of the code. I'm a newbie to Apache mod_rewrite. Also, can you think of a way to stop my css failing. It works fine on mysite.com/about but when i clcik my link that goes to mysite.com/about/jonathon the CSS fails. I'm running the content for the 'jonathon' variable on the same page as about and i guess the extra '/' after about is making the page think it that the CSS folder (which is in my root) is in the same 'directory' as about. But obviously the fake folder of /about/ isnt anywhere else as its still in the root. I know i could use absolute paths for CSS if all else fails. But i'd just prefer to use relative ones IF possible?? Appreciate anyones help Jonathon Quote Link to comment https://forums.phpfreaks.com/topic/225403-rewrite-base-help/#findComment-1166667 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.