Some help finetuning .htaccess? Working but not elegant :)

here’s the client’s php based site: http://littletsunami.com. Links seem SEO friendly now.

Examples:
about.php –> about
portfolio.php?artist=[artistname] –> portfolio/artist/[artistname]
etc.

.htacess:
Options +FollowSymlinks
RewriteEngine on
RewriteRule ^about(/)?$ /about.php/
RewriteRule ^contact(/)?$ /contact.php/
RewriteRule ^faq(/)?$ /faq.php/
RewriteRule ^events(/)?$ /events.php/
RewriteRule ^portfolio(/)?$ /portfolio.php/

RewriteRule ^events/(.) events.php?event_id=$1
RewriteRule ^portfolio/(.
) portfolio.php?artist=$1

1. Instead of listing each single php I would much rather prefer a “wild-card” approach (*.php –> *). I looked into the regular expression tuts but need to admit to my embarrassment that I was not able to figure a working string out, and whatever strings I found here and elsewhere did not work … :confused:

2. I had to edit pretty much all php files and make all paths to external content (imgs, css, js) absolute by adding a /, so to speak ‘rooting’ all paths to external elements, loosing dynamic paths and not liking that. Is this because I am using a rewrite into a virtual directory? Would this problem NOT occur I the rewrite rule wrote into .htm(l) instead? If so then I would very much appreciate if someone was so kind and offered a solution into this direction, because I need to admit that I am now dealing with a time issue (no time left to keep on trying). What I will do for sure is take the string apart for myself to learn what I need to do in the future since this is not the last task like this (RewriteBase / and
RewriteBase /www/littletsunami.com/ did NOT bring about any change).

(3.) One a bit weird irregularity (which I would also be willing to just not look at) is:

  • open http://littletsunami.com/portfolio/Acacia, add a /, press Enter … pretty much all content disappears … Any idea on this one? Is this an issue that needs to get resolved because SEs might index with a / trailing slash, and the visitor from Google, bing etc. might encounter an empty site?

Apart from that, the applied .htaccess rules also work on all alias domains, littletsunamitattoo.com and [URL=“http://littletsunamitattoos.com”]littletsunamitattoos.com (with and without www), so that’s good.

Thanks for helping me here :award:

web server info:

host: Rackspace | Domain Registrar: GoDaddy
config: Ubuntu 8.04.2 LTS (Hardy Heron) | Apache 2.2.8 | DAV 2 | SVN 1.4.6 | PHP 5.2.4-2ubuntu5.10 with Suhosin-Patch | mod_ssl 2.2.8 | OpenSSL 0.9.8g
Linux gsce 2.6.32.9-rscloud #6 SMP x86_64 GNU/Linux

Hi LeeBinder,

Welcome to the SitePoint Apache configuration forum :wave:

1. If I get this correctly you want:

When <url> is requested and <url>.php exists, serve <url>.php instead of <url>

That would be:


RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule ^(.*)$ $1.php [L]

I wouldn’t make the / optional. Either use it or don’t, but don’t create two URLs for the same content (search engines don’t like that).

2. There are multiple solutions to this problem, including the one you picked. Please refer to the section “Relative Links Are Missing!” on Apache’s mod_rewrite

3. The problem here appears to be the added slash.
As per your RewriteRule, what will be requested if you add a slash to the URL is portfolio.php?artist=Acacia/ , i.e. the / becomes part of the artist name to look for. Since there is no such artist (right?), your website doesn’t have any content because it doesn’t know what it should show.
It’s best in cases like these to first check if the requested artist does exist, and if it doesn’t let your scripting language throw a 404 not found error (by sending http headers).
That way people (and search engines) can pick up that the requested site doesn’t exist and forget about it, instead of wondering what it is they’re looking at.

Lastly, I would recommend to pick one domain, and stick to that. Then 301 redirect all domains to that single domain. That way search engines know it’s all one and the same website and won’t penalize you for duplicate content.

For example


RewriteCond %{HTTP_HOST} !^www\\.littletsunamitattoos\\.com$ [NC]
RewriteRule .? http://www.littletsunamitattoos.com%{REQUEST_URI} [L,R=301]

I took [noparse]www.littletsunamitattoos.com[/noparse] as an example here, but of course that’s entirely up to you.

HTH :slight_smile:

Hi ScallioXTX,

great, thanks a lot! Am off to a course now so can’t reply a whole lot and neither test, so in advance just one thing, re. 1: no, the other way around: the task was to cut all .php file extensions and instead have the URL end in what looks like a folder. I was told that’s what SEs prefer, but maybe that was wrong? about.php is as good for SEs as is about or about/ or about.htm?

I’m out all day & night now and should be able to get back into this tomorrow morning.

Thanks,
Lee

No, number 1 does what you want it to; serve about.php when /about is requested :slight_smile:

alright, thanks ScallioXTX, in other words the task given to me was defined the wrong way around to begin with. It seems I should have questioned and researched by myself instead of simply executing … :confused:

Huh? You did want to load about.php when /about is requested, right?
That’s what your code did, and what my code does.

no, the task I was given was to turn name.php –> name. That’s what my code does = the OTHER way around from your code. Sorry, that’s the way it is and which you can verify yourself by going to e.g. http://littletsunami.com/events … it will NOT redirect to events.php (.htaccess with content from my 1st posting is active).

Again (most important): do Google and bing have PREFERENCES regarding indexing, maybe like this:

  1. .htm or html
  2. .php, .asp etc.
  3. /foldername

?

Thanks,
Lee

The idea is not to redirect to /events.php, but to show /events.php when /events is requested. From what I can see that works :slight_smile:

AFAIK search engines don’t have a huge preference over any URL structure, but if you have a chance to pick one I’m pretty sure they’d recommend 3 because it’s the most clean and gives you chance to use keywords in there (moderately, don’t keyword stuff).

HTH

As awkward as it feels to state, but what you say does not reflect reality: http://littletsunami.com/events does NOT redirect to [url=http://littletsunami.com/events.php]http://littletsunami.com/events.php … may I request you to please click onto the 1st link :rolleyes:

AFAIK search engines don’t have a huge preference over any URL structure
aha … :eek:

but if you have a chance to pick one I’m pretty sure they’d recommend 3
to double check with you: in my list 3. is folder or virtual folder, which would contradict you writing before I should redirect from (virtual) folder to .php. Or in other words, we WERE/ARE on the right track with our approach and what we applied in the .htaccess…

because it’s the most clean and gives you chance to use keywords in there
ah, you mean use SE and site/page relevant keywords in .htaccess for the virtual folder redirect.

(moderately, don’t keyword stuff).

I never said /about redirects to /about.php, I said /about.php shows /about.php, which is something else entirely.

If I am the visitor, you are /about and a friend of yours is /about.php and I ask you a question, you could either tell me to ask your friend /about.php (redirect) or you could ask your friend /about.php and then tell me what he said.

The technique is well known and I’m 100% sure you’re doing the correct thing!

Again, not redirect, “show instead of”. And does comply with what I said :slight_smile:
And yes, we are on the right track. Could you show me what you have now?

Yes. Your old structure already contained names, but in a rather standard setup people use numbers to identify a website, like shop.php?pid=120
Of course /shop/baseball-bat is a lot more neat. But this technique is more relevant for users --who can instantly see a description of the site they’re going to instead of some seemingly random URL-- than for search engines.

I recently watched a video where Matt Cutts said something along the lines of: If you’re building a new website and have the opportunity to create friendly URLs go for it, but if you have an existing site it’s not worth the trouble to change it. Just goes to show how minor a factor it is.

Hi ScallioXTX, it’s dawning now, the diffs between SHOW/ DISPLAY and redirect - thanks for your elaborating efforts, we’ll discuss all of this today.

Respect,
Lee

So here’s a summary/ digest of above material from ScallioXTX:

  • accdg. to one of the current Internet Gurus, Matt Cutts, URL rewriting of existing sites is a minor SEO factor: “If you’re building a new website and have the opportunity to create friendly URLs go for it, but if you have an existing site it’s not worth the trouble to change it.”

SEO friendly link formatting in detail:

  • both, file and folder request, should be served and work: when <url> is requested and <url>.php exists, serve <url>.php:
    RewriteCond %{REQUEST_FILENAME}.php -f
    RewriteRule ^(.*)$ $1.php [L]
  • /foldername is preferred over filename .htm/html/.php/.asp etc. AFAIK search engines don’t have a huge preference over any URL structure, but if you have a chance to pick one I’m pretty sure they’d recommend /foldername because it’s the most clean and gives you chance to use keywords in there (SE and site/page relevant keywords in .htaccess for the virtual folder redirect - moderately, don’t keyword stuff)."
  • if a requested URL does not exist, let the used scripting language throw a ‘404 not found’ error by sending http headers
  • it is recommend to only pick one domain and stick to that, then 301 redirect all domains to that single domain. That way search engines know it’s all one and the same website and won’t penalize you for duplicate content.
    Example:
    RewriteCond %{HTTP_HOST} !^www\.littletsunamitattoo\.com$ [NC]
    RewriteRule .? http://www.littletsunamitattoo.com%{REQUEST_URI} [L,R=301]