Forum Moderators: phranque

Message Too Old, No Replies

.htaccess redirects, symlinks and a confused newbie

Site links redirect to .html/.php-less extensions

         

marchsl11

2:29 pm on Dec 4, 2011 (gmt 0)

10+ Year Member



Hello everyone,

I am not familiar with .htaccess files/symlinks, so any help is much appreciated.

My company has two websites -- one of which they wanted me to clone to replace the other. They are on two different servers.

They had me transfer the website files, reconfigure to a new database on a new server, and then make cosmetic changes.

However, I am finding that none of the links on the clone (apart from the home page) actually work. For instance, if you click "What's New" this should link to the Who We Are page. The URL it links to is: [url]who-we-are[/url] (without any extension).

There is a .php file on public_html that is titled "who-we-are.php." The absence of an extension in the URL made me think there was an .htaccess file, and there was:

Options -MultiViews
Options +FollowSymLinks
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
#RewriteRule ^(.*)$ $1.php [L,QSA]

RewriteRule ^search([\/]?)$ index.php?option=collection-products&section=collection&%{QUERY_STRING} [L,QSA]

RewriteRule ^page\/([a-zA-Z0-9_-]+)([\/]?)$ index.php?option=pages&url=$1&%{QUERY_STRING} [L,QSA]

RewriteRule ^product\/([a-zA-Z0-9_-]+)\/([a-zA-Z0-9_-]+)([\/]?)$ index.php?option=product&category=$1&producturl=$2&%{QUERY_STRING} [L,QSA]

RewriteRule ^products\/([a-zA-Z0-9_-]+)([\/]?)$ index.php?option=collection-products&section=collection&productcat=$1&%{QUERY_STRING} [L,QSA]
RewriteRule ^products\/([a-zA-Z0-9_-]+)\/([a-zA-Z0-9_-]+)([\/]?)$ index.php?option=collection-products&section=collection&category=$1&productcat=$2&%{QUERY_STRING} [L,QSA]
RewriteRule ^products\/([a-zA-Z0-9_-]+)\/([a-zA-Z0-9_-]+)\/([a-zA-Z0-9_-]+)([\/]?)$ index.php?option=collection-products&category=$1&section=collection&subcategory=$2&productcat=$3&%{QUERY_STRING} [L,QSA]


RewriteRule ^collection\/([a-zA-Z0-9_-]+)([\/]?)$ index.php?option=collection&section=collection&category=$1&%{QUERY_STRING} [L,QSA]
RewriteRule ^collection\/([a-zA-Z0-9_-]+)\/([a-zA-Z0-9_-]+)([\/]?)$ index.php?option=collection&section=collection&category=$1&subcategory=$2&%{QUERY_STRING} [L,QSA]

#RewriteRule ^detail\/([a-zA-Z0-9_-]+)\/([a-zA-Z0-9_-]+)([\/]?)$ index.php?option=cat_page_more&section=$1&category=$2&%{QUERY_STRING} [L,QSA]

#RewriteRule ^philanthropy([\/]?)$ index.php?option=our-work&section=philanthropy&&%{QUERY_STRING} [L,QSA]
RewriteRule ^philanthropy\/([a-zA-Z0-9_-]+)([\/]?)$ index.php?option=cat_pages&section=philanthropy&category=$1&%{QUERY_STRING} [L,QSA]
RewriteRule ^philanthropy\/([a-zA-Z0-9_-]+)\/([a-zA-Z0-9_-]+)([\/]?)$ index.php?option=cat_page_detail&section=philanthropy&category=$1&pageurl=$2&%{QUERY_STRING} [L,QSA]

RewriteRule ^our-work\/([a-zA-Z0-9_-]+)([\/]?)$ index.php?option=cat_pages&section=our-work&category=$1&%{QUERY_STRING} [L,QSA]
RewriteRule ^our-work\/([a-zA-Z0-9_-]+)\/([a-zA-Z0-9_-]+)([\/]?)$ index.php?option=cat_page_detail&section=our-work&category=$1&pageurl=$2&%{QUERY_STRING} [L,QSA]

RewriteRule ^([a-zA-Z0-9_-]+)\/([a-zA-Z0-9_-]+)([\/]?)$ index.php?option=cat_page_detail&section=$1&pageurl=$2&%{QUERY_STRING} [L,QSA]

RewriteRule ^our-services([\/]?)$ index.php?option=cat_pages&section=our-services&%{QUERY_STRING} [L,QSA]
#RewriteRule ^philanthropy([\/]?)$ index.php?option=cat_pages&section=philanthropy&%{QUERY_STRING} [L,QSA]
RewriteRule ^conceptual-gift-design([\/]?)$ index.php?option=cat_pages&section=conceptual-gift-design&%{QUERY_STRING} [L,QSA]

#RewriteRule ^our-services\/([a-zA-Z0-9_-]+)([\/]?)$ index.php?option=cat_page_detail&section=our-services&pageurl=$1&%{QUERY_STRING} [L,QSA]


#RewriteRule ^our-work([\/]?)$ index.php?option=collection&section=our-work&%{QUERY_STRING} [L,QSA]



RewriteRule ^([a-zA-Z0-9_-]+)([\/]?)$ index.php?option=$1&%{QUERY_STRING} [L,QSA]


It references a symlink. On the original website, there are two symlinks in the root/ folder (not public_html) that are titled: www -> public_html; and then another called, access_logs -> ../domlogs/artmorp1.

I assume I need to add the symlinks to the new server for the new site, but can anyone help me understand what is actually going on in this situation?

It would help if you could point out what the problem with the clone, and give me suggestions as to how to fix it.

Many thanks.

lucy24

10:55 pm on Dec 4, 2011 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Would it help if you rounded up the person who originally wrote the htaccess and forced them to sit down and learn the basics of mod_rewrite [httpd.apache.org]?

I'm trying to decipher the question, but I just can't drag my eyes away from that recurring

([\/]?)$

where a simple

/?$

will do.

marchsl11

8:13 am on Dec 5, 2011 (gmt 0)

10+ Year Member



Hi Lucy:

Unfortunately this person has long disappeared by now. The question is basically:

1. What is this code trying to accomplish?

2. And what role, if any, do symlinks have to play in this (meaning, how do I get the URL's to properly direct to the .php files using it)?

Many thanks.

lucy24

9:47 am on Dec 5, 2011 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



1. What is this code trying to accomplish?

Search me. You'd have to ask the person who wrote it. Would you settle for "What does this code accomplish?"?

2. And what role, if any, do symlinks have to play in this (meaning, how do I get the URL's to properly direct to the .php files using it)?

Don't look at me. There are certain words and concepts that I've got a permanent mental block on, and symlinks appears to be one of them :(

But, having dragged my eyes away from ([\/]?)$ I am now staring blankly at the equally common

RewriteRule ^search/?$ index.php?option=collection-products&section=collection&%{QUERY_STRING} [L,QSA]


and trying to figure out what that %{QUERY_STRING} is doing there. In conjunction with QSA it would seem to mean that you've now got two copies of everything in the original query string: one from the %{QUERY_STRING} in the target, and a second from the QSA flag.

Do a quick Forums search for "query string" + "boilerplate" so I don't have to paste it in all over again.

The absence of an extension in the URL made me think there was an .htaccess file, and there was

Hm, well, that's interesting reasoning. Though the idea of a site without an htaccess file-- unless you've got your own server and it's all in the config file-- would make anyone's blood run cold. You're not letting any and all Central European robots run wild all over the site are you?

Anyway, the existing htaccess is giving me a headache. How 'bout if you just throw it out and start clean. Pick a link-- any link-- and explain #1 what it's supposed to do, and #2 what it actually does do.

Do not say "It doesn't work." We need to know how it doesn't work. Use an extension like LiveHeaders to see what kind of detours, if any, you're being sent on between the link you click and the (I assume) error page you end up on. Use example.com (or .org or .net, with or without www.) in all examples so it doesn't all get turned into unreadable auto-links.

g1smd

8:13 pm on Dec 5, 2011 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



There's so much wrong with the code that it's difficult to know where to start.

All of the above problems apply and need to be fixed, but
RewriteRule ^search/?$
as a pattern promotes duplicate content because URLs both with or without a trailing slash return the same content.

Pick one version to be the canonical URL and redirect the other.

It's also likely that the first rewrite in the list should actually be the very last rule. Rules should be listed from most specific to most general and (.*) meaning "everything" is as general as it can get.