kirkh34 Posted December 20, 2010 Share Posted December 20, 2010 i have been on dozens of sites trying different code for a mod rewrite so I can have a friendlier url for seo... i have no idea why it's not working i am stumped.. i am using a rewrite to redirect to www and that works fine... help is appreciated Options +FollowSymlinks RewriteEngine on rewritecond %{http_host} ^domain.com [nc] rewriterule ^(.*)$ http://www.domain.com/$1 [r=301,nc] RewriteRule http://www.domain.com/photo/(.*)/(.*)/$ /photo.php?$1=$2 i have also tried it with the carrot at the beginnign with no luck... and with the full url.. i have tried countless ways from googling and never does it work Quote Link to comment https://forums.phpfreaks.com/topic/222220-mod-rewrite/ Share on other sites More sharing options...
johnny86 Posted December 20, 2010 Share Posted December 20, 2010 RewriteRule photo\/([^\/]+)\/([^\/]+) photo.php?$1=$2 [nc] Maybe that could work? Quote Link to comment https://forums.phpfreaks.com/topic/222220-mod-rewrite/#findComment-1149574 Share on other sites More sharing options...
kirkh34 Posted December 20, 2010 Author Share Posted December 20, 2010 nope... still no go...just seems very strange... i've tried so many options and none of them work Quote Link to comment https://forums.phpfreaks.com/topic/222220-mod-rewrite/#findComment-1149582 Share on other sites More sharing options...
johnny86 Posted December 20, 2010 Share Posted December 20, 2010 I dont know what to say. I tested my rule and it worked just fine on my server. It should work Quote Link to comment https://forums.phpfreaks.com/topic/222220-mod-rewrite/#findComment-1149584 Share on other sites More sharing options...
kirkh34 Posted December 20, 2010 Author Share Posted December 20, 2010 im not sure what to do. the module is enabled... shouldn't this change my url when i access the page? am i missing any steps? Quote Link to comment https://forums.phpfreaks.com/topic/222220-mod-rewrite/#findComment-1149589 Share on other sites More sharing options...
johnny86 Posted December 20, 2010 Share Posted December 20, 2010 Mod rewrite rewrites requests internally to specified location. So unless you redirect with [R=STATUS] at the end of your rule, the rewrite won't show to the client browsing your site. RewriteRule photo\/([^\/]+)\/([^\/]+) photo.php?$1=$2 [nc] That will rewrite all requests that matches: photo/something_untill_slash/something_untill_slash_or_end and redirect the request to photo.php with parameters something_untill_slash=something_untill_slash_or_end which will be available then for PHP through $_GET. Client doesn't see that happening. However if a client visits photo.php?something=something no rewriting is being done and the URL will presist at client side. Have you tried to print_r($_GET) in your photo.php? See if the params are passed Quote Link to comment https://forums.phpfreaks.com/topic/222220-mod-rewrite/#findComment-1149609 Share on other sites More sharing options...
kirkh34 Posted December 21, 2010 Author Share Posted December 21, 2010 so what I'm really trying to do is get it to show in the url... right now if you type in domain.com/photo/(id) it goes to the old url.. i want the opposite really... how can this be done? Quote Link to comment https://forums.phpfreaks.com/topic/222220-mod-rewrite/#findComment-1149770 Share on other sites More sharing options...
johnny86 Posted December 21, 2010 Share Posted December 21, 2010 So if you type in domain.com/photo/(id) what is the url you get? and what is exactly the url you want it to be? Quote Link to comment https://forums.phpfreaks.com/topic/222220-mod-rewrite/#findComment-1149802 Share on other sites More sharing options...
kirkh34 Posted December 21, 2010 Author Share Posted December 21, 2010 I was thinking of it backwards, as if you could do the rewrite and it change all your urls... i get it now... I will have to change all the urls myself... so...another question, is there anyway I can have the title as the url domain.com/photo-title-goes-here i added a get variable to the url for the title with the hyphens in between each word... can I somehow hide the ID variable and only show the name variable? Quote Link to comment https://forums.phpfreaks.com/topic/222220-mod-rewrite/#findComment-1149841 Share on other sites More sharing options...
johnny86 Posted December 21, 2010 Share Posted December 21, 2010 I'm assuming you want to make your urls look like this now: http://www.domain.com/photo-title As you said this means you have to change all your links in the source to that format. Using mod_rewrite you could do something like this: RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule (.*) photo.php?title=$1 Now this requires you to change the code in photo.php to compare $_GET['title'] to your database against photo titles and if matched -> show the photo. This raises new problem because you cannot have two photos with the same title or they'll get mixed. So you need some kind of way to identify your photos if you allow users to submit photos with the same title. Quote Link to comment https://forums.phpfreaks.com/topic/222220-mod-rewrite/#findComment-1149880 Share on other sites More sharing options...
kirkh34 Posted December 22, 2010 Author Share Posted December 22, 2010 yeah... and really I'd really like to keep everything with the ID as far as the database goes... for now I just have domain.com/title-goes-here-0983 <--id number... It's not a big deal i suppose... I mainly just wanted it like this for SEO...so I think I'm good to go... thanks a lot for your responses johnny! i appreciate it Quote Link to comment https://forums.phpfreaks.com/topic/222220-mod-rewrite/#findComment-1150208 Share on other sites More sharing options...
johnny86 Posted December 22, 2010 Share Posted December 22, 2010 Glad I could help you! Quote Link to comment https://forums.phpfreaks.com/topic/222220-mod-rewrite/#findComment-1150216 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.