Jump to content

mod rewrite


kirkh34

Recommended Posts

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

 

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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?

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.