Part 1
Well, I have two major files for my site:
index.php and
topics.php. The
index.php page doesn't change, so it's not really a concern, however, I have hundreds of pages that are generated through
topics.php. My site has certain categories, which have sections, which have pages, so I used to have links like:
/topics.php?category=about§ion=legal&page=priva cy
I've used some rewrites to use static links, so that link is now:
/topics/about/legal/privacy
However, I am concerned about the efficiency because I am running on a shared host. Here's the code I used for the rewriting:
Code:
RewriteRule ^topics/([^/]+)/([^/]+)/([^/]+)/?$ /topics.php?category=$1§ion=$2&page=$3 [L]
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /topics\.php\?category=([^&]+)§ion=([^&]+)&page=([^\ ]+)\ HTTP/
RewriteRule ^topics\.php$ http://www.domain.com/topics/%1/%2/%3? [R=301,L]
RewriteRule ^topics/([^/]+)/([^/]+)/?$ /topics.php?category=$1§ion=$2 [L]
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /topics\.php\?category=([^&]+)§ion=([^\ ]+)\ HTTP/
RewriteRule ^topics\.php$ http://www.domain.com/topics/%1/%2? [R=301,L]
RewriteRule ^topics/([^/]+)/?$ /topics.php?category=$1 [L]
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /topics\.php\?category=([^\ ]+)\ HTTP/
RewriteRule ^topics\.php$ http://www.domain.com/topics/%1? [R=301,L]
RewriteRule ^topics/?$ /topics.php [L]
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /topics\.php\ HTTP/
RewriteRule ^topics\.php$ http://www.domain.com/topics/? [R=301,L]
I was wondering if I could make it smaller and still get the same results (because every page is not going to have all three variables). If not, might there be a more efficient way of doing this?
Part 2
I can't figure out why Google is sometimes browsing with double slashes (i.e.
/forums//search.php), so I put in some code to remove multiple slashes:
Code:
RewriteCond %{REQUEST_URI} ^(.*)//(.*)$
RewriteRule . %1/%2 [R=301,L]
I am just as concerned about this piece of code, if not more, than the other code in my .htaccess. I feel that this is incredibly inefficient. The problem is, I want to have a since piece of code that removes various numbers of multiple slashes (i.e.
/oldsite//forum///index.php rewriting to
/oldsite/forum/index.php). I know that there has to be a better method out there than just using the code I have because that redirects for each additional slash instead of giving a single, clean redirect.
Part 3
I'm not sure if anyone will know this or not... If a RewriteRule uses multiple RewriteCond statements, will Apache stop checking the RewriteCond statements under the first condition that evaluates to false? That would make the most sense, but I'm not sure how the Rewrite Module works
Thanks for taking the time to read! Any help will be greatly appreciated!
