homepage Welcome to WebmasterWorld Guest from 54.237.98.229
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Pubcon Platinum Sponsor 2014
Home / Forums Index / Code, Content, and Presentation / Apache Web Server
Forum Library, Charter, Moderators: Ocean10000 & incrediBILL & phranque

Apache Web Server Forum

This 38 message thread spans 2 pages: < < 38 ( 1 [2]     
.htaccess redirect issue - robots.txt
robots.txt issue with redirect
tommydamic68



 
Msg#: 4636889 posted 11:50 am on Jan 12, 2014 (gmt 0)

Hello all,

Hoping someone can help with this issue with my .htaccess redirect. So a bit of history, I had a Vbulletin (3.8) forum script that had the .htaaccess file you see below, I was using VBSEO (an SEO script that change the URL to be search engine friendly.) I then moved my forum over to Xenforo software, so the threads needed to be redirected as well as my URL - here is the additional code I was given which I just dropped in the top of the .htaccess file.

Options -Indexes
RewriteEngine On
RewriteCond %{HTTP_HOST} www.mysite.com$
RewriteRule ^(.*)$ http://mysite.com/$1 [R=301,L]
RewriteRule ^[^/]+/.+-([0-9]+)/$ /community/index.php?threads/$1/ [R=301,L]
RewriteRule ^forum\.php$ /community/ [R=301,L]
RewriteRule ^(images|dir2|dir3|dir4)/.*$ - [S=1]
RewriteRule ^.*$ /community/ [R=301,L]


The problem is this,
when looking for www.mysite.com/robots.txt it redirects back to www.mysite.com

Please help with this issue, its frustrating to say the least! Also, I would love to be able to rewrite my entire .htaccess file itself with all the extra "stuff" it has gathered over the years and bring it up date with 2014 - perhaps an .htaccess guru could clean this bad boy up!

Thanks in advance!

Tom

Options -Indexes
RewriteEngine On
RewriteCond %{HTTP_HOST} www.mysite.com$
RewriteRule ^(.*)$ http://mysite.com/$1 [R=301,L]
RewriteRule ^[^/]+/.+-([0-9]+)/$ /community/index.php?threads/$1/ [R=301,L]
RewriteRule ^forum\.php$ /community/ [R=301,L]
RewriteRule ^(images|dir2|dir3|dir4)/.*$ - [S=1]
RewriteRule ^.*$ /community/ [R=301,L]

# Use PHP 5.3
AddType application/x-httpd-php53 .php

# Ticket PBB-18872701
<IfModule mod_suphp.c>
suPHP_ConfigPath /home/admin/public_html
<Files php.ini>
order allow,deny
deny from all
</Files>
</IfModule>
# Ticket PBB-18872701

DirectoryIndex index.php
#RewriteEngine Off

# Comment the following line (add '#' at the beginning)
# to disable mod_rewrite functions.
# Please note: you still need to disable the hack in
# the vBSEO control panel to stop url rewrites.
RewriteEngine On

RewriteCond %{HTTP_HOST} ^mysite.com$
RewriteRule ^/?$ "http\:\/\/www\.mysite\.com\/" [R=301,L]

RewriteCond %{HTTP_HOST} ^mysite.com$
RewriteRule ^forum\.php\/?(.*)$ "http\:\/\/www\.mysite\.com\/forum\.php$1" [R=301,L]

# Some servers require the Rewritebase directive to be
# enabled (remove '#' at the beginning to activate)
# Please note: when enabled, you must include the path
# to your root vB folder (i.e. RewriteBase /forums/)
#RewriteBase /

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

RewriteRule ^((urllist|sitemap).*\.(xml|txt)(\.gz)?)$ vbseo_sitemap/vbseo_getsitemap.php?sitemap=$1 [L]

RewriteCond %{REQUEST_URI} !(admincpvioc1/|modcpvioc2/|cron|vbseo_sitemap)
RewriteRule ^((archive/)?(.*\.php(/.*)?))$ vbseo.php [L,QSA]

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !/(admincpvioc1|modcpvioc2|clientscript|cpstyles|images)/
RewriteRule ^(.+)$ vbseo.php [L,QSA]

<Files 403.shtml>
order allow,deny
allow from all
</Files>

RewriteCond %{HTTP_USER_AGENT} ^Baiduspider.* [NC]

#RewriteCond %{HTTP_HOST} ^mysite.com$
#RewriteRule ^/?$ "http\:\/\/www\.mysite\.com\/" [R=301,L]

#RewriteCond %{HTTP_HOST} ^mysite.com$
#RewriteRule ^forum\.+\/?(.*)$ "http\:\/\/www\.mysite\.com\/forum\.php$1" [R=301,L]
# Expire images header
ExpiresActive On
ExpiresDefault A0
ExpiresByType image/gif A2592000
ExpiresByType image/png A2592000
ExpiresByType image/jpg A2592000
ExpiresByType image/jpeg A2592000
ExpiresByType image/ico A2592000
ExpiresByType text/css A2592000
ExpiresByType text/javascript A2592000
# compress text, html, javascript, css, xml:
AddOutputFilterByType DEFLATE text/plain
AddOutputFilterByType DEFLATE text/html
AddOutputFilterByType DEFLATE text/xml
AddOutputFilterByType DEFLATE text/css
AddOutputFilterByType DEFLATE application/xml
AddOutputFilterByType DEFLATE application/xhtml+xml
AddOutputFilterByType DEFLATE application/rss+xml
AddOutputFilterByType DEFLATE application/javascript
AddOutputFilterByType DEFLATE application/x-javascript
# Or, compress certain file types by extension:
<files *.html>
SetOutputFilter DEFLATE
</files>

RewriteEngine On
RewriteRule ^Microsoft-Server-ActiveSync$ hgpush/index.php

 

tommydamic68



 
Msg#: 4636889 posted 10:19 am on Feb 6, 2014 (gmt 0)

Thank g1smd. I truly appreciate your input. I am not a pro at this, please correct me if I am wrong, you mean change it like below? And also - where is the code with the missing L flag? please point me in that direction.


# Redirect index.php
RewriteEngine on
RewriteCond %{HTTP_HOST} ^www\.example\.com$ [OR]
RewriteCond %{REQUEST_URI} ^/$

# Redirect index.aspx|html|php|shtml|cfm|pl
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /([^/]+/)*(default|index)\.(php?|aspx?|s?html?|cfm?|pl?)\ HTTP

# RewriteVBSEO
RewriteEngine on
RewriteRule f[\d]+/.+-([\d]+)/index([\d]+).html showthread.php?t=$1&page=$2 [NC,L]
RewriteRule f[\d]+/.+-([\d]+)/ showthread.php?t=$1 [NC,L]
RewriteRule f([\d]+)/index([\d]+).html forumdisplay.php?f=$1&page=$2 [NC,L]
RewriteRule f([\d]+)/ forumdisplay.php?f=$1 [NC,L]
RewriteRule ^(([^/]+/)*)(default|index)\.(php?|aspx?|s?html?|cfm?|pl?)$ http://www.example.com/$1? [R=301,L]
RewriteRule ^Microsoft-Server-ActiveSync$ hgpush/index.php
RewriteRule ^$ http://example.com/community/$1 [R=301,L]
RewriteRule ^$ http://example.com/community/$1 [R=301,L]

tommydamic68



 
Msg#: 4636889 posted 10:57 am on Feb 6, 2014 (gmt 0)

Sorry g1smd - i think you meant this below? Also where is the missing l flag, please correct for me.

# Protect htaccess
<files .htaccess="">
order allow,deny
deny from all
</files>

# Don't show directories
Options -Indexes

# ErrorDocument 404 /404.shtml
ErrorDocument 404 /error/bara-index.html
ErrorDocument 500 default

# Use PHP 5.4
AddType application/x-httpd-php54 .php

# Directory Index
DirectoryIndex index.html index.php

# Redirect index.php
RewriteEngine on
RewriteCond %{HTTP_HOST} ^www\.example\.com$ [OR]
RewriteCond %{REQUEST_URI} ^/$
RewriteRule ^$ http://example.com/community/$1 [R=301,L]

# Redirect index.aspx|html|php|shtml|cfm|pl
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /([^/]+/)*(default|index)\.(php?|aspx?|s?html?|cfm?|pl?)\ HTTP
RewriteRule ^(([^/]+/)*)(default|index)\.(php?|aspx?|s?html?|cfm?|pl?)$ http://www.example.com/$1? [R=301,L]
RewriteRule ^Microsoft-Server-ActiveSync$ hgpush/index.php

# Redirect VBSEO
RewriteEngine on
RewriteRule f[\d]+/.+-([\d]+)/index([\d]+).html showthread.php?t=$1&page=$2 [NC,L]
RewriteRule f[\d]+/.+-([\d]+)/ showthread.php?t=$1 [NC,L]
RewriteRule f([\d]+)/index([\d]+).html forumdisplay.php?f=$1&page=$2 [NC,L]
RewriteRule f([\d]+)/ forumdisplay.php?f=$1 [NC,L]

lucy24

WebmasterWorld Senior Member lucy24 us a WebmasterWorld Top Contributor of All Time Top Contributors Of The Month



 
Msg#: 4636889 posted 7:18 pm on Feb 6, 2014 (gmt 0)

Something is seriously wrong here:
RewriteEngine on
RewriteCond %{HTTP_HOST} ^www\.example\.com$ [OR]
RewriteCond %{REQUEST_URI} ^/$

# Redirect index.aspx|html|php|shtml|cfm|pl
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /([^/]+/)*(default|index)\.(php?|aspx?|s?html?|cfm?|pl?)\ HTTP

# RewriteVBSEO
RewriteEngine on


<files .htaccess="">

Is this your own server? I have a hard time believing that any host anywhere wouldn't already have a line in the config file to protect htaccess. I don't understand the syntax though; the expected form is

<FilesMatch "^\.ht">
blahblah
</FilesMatch>

And it's got to be there already. You can test it by simply commenting-out your own rule and then requesting example.com/.htaccess

tommydamic68



 
Msg#: 4636889 posted 7:36 pm on Feb 6, 2014 (gmt 0)

Hi Lucy24 - seriously wrong where?

lucy24

WebmasterWorld Senior Member lucy24 us a WebmasterWorld Top Contributor of All Time Top Contributors Of The Month



 
Msg#: 4636889 posted 9:19 pm on Feb 6, 2014 (gmt 0)

Remember the boilerplate about "why we make you do it yourself"? What I posted was a line-by-line verbatim quote from your earlier post. Look at it again and presently you will say Oh, oops...

:: detour to test site ::

Huh. I kinda expected that set of lines to result in a 500-class error, which would be pretty hard to miss. But I guess the superflous RewriteEngine on line is simply ignored, and then the ... Well, that's where we wait for the "D'oh!" moment.

tommydamic68



 
Msg#: 4636889 posted 9:56 pm on Feb 6, 2014 (gmt 0)

I would greatly appreciate you helping me the proper corrections. I am new to this and just want it right.

Thanks

tommydamic68



 
Msg#: 4636889 posted 1:07 am on Feb 7, 2014 (gmt 0)

ok - how is this? "rewrite engine on" does not need to be there twice i suppose? Also you were right, its safe guarded without the line of code to protect the file. Still can't find where the missing L flag needs to go.

# Don't show directories
Options -Indexes

# ErrorDocument 404 /404.shtml
ErrorDocument 404 /error/bara-index.html
ErrorDocument 500 default

# Use PHP 5.4
AddType application/x-httpd-php54 .php

# Directory Index
DirectoryIndex index.html index.php

# Redirect index.php
RewriteEngine on
RewriteCond %{HTTP_HOST} ^www\.example\.com$ [OR]
RewriteCond %{REQUEST_URI} ^/$
RewriteRule ^$ http://example.com/community/$1 [R=301,L]

# Redirect index.aspx|html|php|shtml|cfm|pl
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /([^/]+/)*(default|index)\.(php?|aspx?|s?html?|cfm?|pl?)\ HTTP
RewriteRule ^(([^/]+/)*)(default|index)\.(php?|aspx?|s?html?|cfm?|pl?)$ http://www.example.com/$1? [R=301,L]
RewriteRule ^Microsoft-Server-ActiveSync$ hgpush/index.php

# Rewrite VBSEO
RewriteRule f[\d]+/.+-([\d]+)/index([\d]+).html showthread.php?t=$1&page=$2 [NC,L]
RewriteRule f[\d]+/.+-([\d]+)/ showthread.php?t=$1 [NC,L]
RewriteRule f([\d]+)/index([\d]+).html forumdisplay.php?f=$1&page=$2 [NC,L]
RewriteRule f([\d]+)/ forumdisplay.php?f=$1 [NC,L]

lucy24

WebmasterWorld Senior Member lucy24 us a WebmasterWorld Top Contributor of All Time Top Contributors Of The Month



 
Msg#: 4636889 posted 2:31 am on Feb 7, 2014 (gmt 0)

RewriteRule ^$ http://example.com/community/$1 [R=301,L]

I did wonder if it was simply a copy-and-paste glitch. This line-- the RewriteRule belonging to the two preceding conditions-- was absent last time around.

If your text editor-- the one you use to build your htaccess file-- does Regular Expressions, search for this pattern:

RewriteRule .+\w$
(Rule without final flag)

While you're at it, check for

RewriteRule \S+ \w[^:\s]+$
(target without leading slash or http: )
or
RewriteRule \S+ \w\S+ \[L\]
(target without leading slash in rules configured as rewrites only)
or
... well, there are lots of possible permutations. That's for testing the htaccess file itself; they're not intended as RewriteRules!

This 38 message thread spans 2 pages: < < 38 ( 1 [2]
Global Options:
 top home search open messages active posts  
 

Home / Forums Index / Code, Content, and Presentation / Apache Web Server
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved