views:

44

answers:

2

Hello everyone, I'm trying to use modrewrite to change my urls from /foo.php to /foo and from /foo.php?lang=en to /en/foo. The problem I have is that I think I need to use 301 redirect to move the .php-less address to the .php address, or else my ranking will be splitted among these 2. But if I use [R=301] the address in the bar changes to the .php one making my pretty url efforts quite useless. What should I do?

I've looked around for any question\tutorial i could find but I can't fully understand modrewrite. The main issue I have is that if I change my .htaccess file then revisit an already visited page the new .htaccess is not working but is somehow caching the old result making correction a real pain. Do you know a workaround?

Thank you,

Mokuchan

A: 

You definitely must look at Apache modul mod_rewrite and general idea of rewriting urls.

http://httpd.apache.org/docs/2.0/mod/mod_rewrite.html

Tomasz Kowalczyk
yes I looked at it and have a general idea but my question is more about seo (and why it's caching my addresses... ugh)
Mokuchan
@Mokuchan - If you went to URLs that were processed by a rule with `[R=301]`, your browser could have cached the redirection and automatically points you at the alternate resource without going to the server first. You'll need to be more specific about what changes you're making that aren't being reflected to know for sure, though.
Tim Stone
I think you got it! What happens is that I change the rewrite rule and it shows the new behaviour on pages not visited before and the old behaviour on pages I already visited (for example adding .php 2 times in the old ones (wrong behaviour of my first regex) and .php 1 time on the new ones)
Mokuchan
If satisfied, please accept ;]
Tomasz Kowalczyk
+1  A: 

Sounds like MultiViews would be a better solution than rewriting the URL. Just put this in your .htaccess. What that will do is essentially, if i type in stackoverflow.com/pages it will first look for a directory named pages, if it can't find it, a file. You can then have stackoverflow.com/pages/view/some/page where /view/some/page is the query.

Options Indexes FollowSymLinks Includes MultiViews

Edit To get the /view/some/page/ use $_SERVER['PATH_INFO'];

Robert
Seems nice to me... I still have to change page?lang=en to /en/page! I think I need to put the code to do that after your code so that it retrieves the file first then apply the url trasformation. Am i correct?
Mokuchan
I don't think that using `MultiViews` is *ever* a better solution, personally..
Tim Stone
this isn't what MultiViews was designed for really, it was designed for automatic content negotiation. If there's two (or more) versions of a document in different languages, MultiViews allows the server to send the document which the browser specifies it prefers.
Turnor