Forum Moderators: phranque

Message Too Old, No Replies

.htaccess trouble

space to hyphen - force lowercase - non-www to www

         

bkrenzin

8:33 pm on Nov 10, 2010 (gmt 0)

10+ Year Member



Below is my code. some is in my vhost file some is in .htaccess.

I am getting an error and time-out from the server.

Can someone please advise.

Here is the response from the server - (please note the error and time-out at the end)

URL=h**p://mysite.com/dog Supplies
Result code: 301 (MovedPermanently / Moved Permanently)
Date: Wed, 10 Nov 2010 20:35:04 GMT
Server: Apache/2.2.9 (Debian) PHP/5.2.6-1+lenny8 with Suhosin-Patch mod_ssl/2.2.9 OpenSSL/0.9.8g
Location: h**p://mysite.com/dog supplies
Vary: Accept-Encoding
Content-Length: 382
Content-Type: text/html; charset=iso-8859-1
New location: h**p://mysite.com/dog supplies

URL=h**p://mysite.com/dog supplies
Result code: 301 (MovedPermanently / Moved Permanently)
Date: Wed, 10 Nov 2010 20:35:04 GMT
Server: Apache/2.2.9 (Debian) PHP/5.2.6-1+lenny8 with Suhosin-Patch mod_ssl/2.2.9 OpenSSL/0.9.8g
Location: h**p://www.mysite.com/dog supplies
Vary: Accept-Encoding
Content-Length: 386
Content-Type: text/html; charset=iso-8859-1
New location: h**p://www.mysite.com/dog supplies

URL=h**p://www.mysite.com/dog supplies
Error: A timeout occured, could not process your URL.

Regards,

Brian


<VirtualHost *:80>
ServerAdmin webmaster@mysite.com
ServerName mysite.com
ServerAlias www.mysite.com
DocumentRoot /mnt/www/mysite
<Directory />
Options FollowSymLinks
AllowOverride All
</Directory>
<Directory /mnt/www/mysite>
Options -Indexes FollowSymLinks MultiViews
AllowOverride All
Order allow,deny
allow from all
</Directory>

ScriptAlias /cgi-bin/ /usr/lib/cgi-bin/
<Directory "/usr/lib/cgi-bin">
AllowOverride None
Options +ExecCGI -MultiViews +SymLinksIfOwnerMatch
Order allow,deny
Allow from all
</Directory>

ErrorLog /var/log/apache2/error_mysite_com.log

# Possible values include: debug, info, notice, warn, error, crit,
# alert, emerg.
LogLevel warn

CustomLog /var/log/apache2/access_mysite_com.log combined

Alias /doc/ "/usr/share/doc/"
<Directory "/usr/share/doc/">
Options Indexes MultiViews FollowSymLinks
AllowOverride None
Order deny,allow
Deny from all
Allow from 127.0.0.0/255.0.0.0 ::1/128
</Directory>
Options +FollowSymLinks -MultiViews
RewriteEngine on


RewriteMap lowercase int:tolower
RewriteCond $1 [A-Z]
RewriteRule ^/(.*)$ /${lowercase:$1} [R=301,L,NE]

RewriteCond %{HTTP_HOST} ^[^\.]+\.[^\.]+$
RewriteRule ^/(.*)$ http://www.%{HTTP_HOST}/$1 [R=301,L,NE]



</VirtualHost>

*************Below is from .htaccess**************

Options +FollowSymLinks
RewriteEngine on
FileETag MTime Size

# Prevent Directoy listing
Options -Indexes

# Prevent Direct Access to files
<FilesMatch "\.tpl">
Order deny,allow
Deny from all
</FilesMatch>

# Replace spaces with hyphens
RewriteRule ^([^\ ]*)\ (.*)$ $1-$2 [E=rspace:yes,N]
# Redirect to update URL in search engine listings and browsers
RewriteCond %{ENV:rspace} yes
RewriteRule (.*) http://%{HTTP_HOST}/$1 [R=301,L]

# SEO URL Settings
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)\?*$ index.php?_route_=$1 [L]

bkrenzin

6:16 pm on Nov 12, 2010 (gmt 0)

10+ Year Member



bump

wilderness

6:25 pm on Nov 12, 2010 (gmt 0)

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



FWIW,
You may "bump" this every five minutes (although that may put you on Brett's bad side), and your not likely to get an answer until Jim returns.

bkrenzin

6:44 pm on Nov 12, 2010 (gmt 0)

10+ Year Member



Thanks for the scolding..... I guess using a bump makes me a jerk. Sorry to everyone for my apparent indiscretion. I really respect this forum. I have learned a lot from it over the years. Last thing I was attempting to do was appear to be arrogant and rude.

jdMorgan

2:23 am on Nov 18, 2010 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



This rule has a functional error in it, because the query string is not seen by RewriteRule:

# SEO URL Settings
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)\?*$ index.php?_route_=$1 [L]

Therefore, this rule will never be invoked.

If you wish to require a query string on the requested URL, then you'll need an additional RewriteCond:

# SEO URL Settings
RewriteCond %{QUERY_STRING} !=""
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?_route_=$1 [L]

However, there is still the possibility that your space-to-hyphen converter rule is causing the problem (due to an obscure, long-standing, and un-corrected mod_rewrite bug). Have you commented-out that rule (and only that rule) to see if that makes the timeout problem go away? (It is difficult to assess the scope of your problem without knowing what requests do and do not trigger this timeout, or whether and how the problem is identified in your server error log.)

I should also comment that once we get this code working, the whole thing needs to be re-assessed with an eye toward preventing chained/stacked/multiple redirects. For example, the spaces should be converted to hyphens, the hostname canonicalized, and the lowercase conversion done all at once, then the four combinations of any two errors, then each error on its own. This prevents a client from getting multiple redirects from one (really) badly-formed request -- something that search engines don't much like.

Also, are you really using content-negotiation on your site? If not, disable MultiViews to preserve sanity when trying to use mod_rewrite...

Jim

bkrenzin

4:17 am on Nov 18, 2010 (gmt 0)

10+ Year Member



Jim:

Thank you.

I will attempt to add results and final code to this thread when complete.

Your help is greatly appreciated and respected.


With Best Regards,

Brian

bkrenzin

1:06 am on Nov 19, 2010 (gmt 0)

10+ Year Member



Jim:

I gathered some data to review from your questions above
If I comment out the space to hyphen the loop goes away.... but desired result is not achieved.

Best regards.

Brian



*****************************************
***** With Space To Hyphen In Use ******
*****************************************
TEST 1 - undesired result

Server Response:
Results of the GSiteCrawler Server-Test
Tested at 11/19/2010 12:29:24 AM / from 64.216.106.32:

URL=h**p://www.mysite.com/dog-training-equipment/Grain Valley-Case
Result code: 301 (MovedPermanently / Moved Permanently)
New location: h**p://www.mysite.com/dog-training-equipment/grain valley-case

URL=h**p://www.mysite.com/dog-training-equipment/grain valley-case
Result code: 301 (MovedPermanently / Moved Permanently)
New location: h**p://www.mysite.com/grain-valley-case

URL=h**p://www.mysite.com/grain-valley-case
Error: A timeout occurred, could not process your URL.

---> There is no error recorded in the error log. <---

=================================================================

TEST 2

Results of the GSiteCrawler Server-Test
Tested at 11/19/2010 12:44:44 AM / from 64.216.106.32:

URL=h**p://www.mysite.com/dog-training-equipment/grain valley-case
Result code: 301 (MovedPermanently / Moved Permanently)
New location: h**p://www.mysite.com/grain-valley-case

URL=h**p://www.mysite.com/grain-valley-case
Result code: 200 (OK / OK)

=================================================================

TEST 3

Results of the GSiteCrawler Server-Test
Tested at 11/19/2010 12:46:35 AM / from 64.216.106.32:

URL=h**p://www.mysite.com/dog-training-equipment/Grain-Valley-Case
Result code: 301 (MovedPermanently / Moved Permanently)
New location: h**p://www.mysite.com/dog-training-equipment/grain-valley-case

URL=h**p://www.mysite.com/dog-training-equipment/grain-valley-case
Result code: 200 (OK / OK)

=================================================================

TEST 3 - undesired result

Results of the GSiteCrawler Server-Test
Tested at 11/19/2010 12:48:42 AM / from 64.216.106.32:

URL=h**p://www.mysite.com/dog-training-equipment/grain valley case
Result code: 200 (OK / OK)

jdMorgan

3:14 am on Nov 30, 2010 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Sorry, I lost the thread...

Did you disable MultiViews as mentioned above?

Jim